@itwin/presentation-testing 3.4.0-dev.59 → 3.4.0-dev.60

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 (37) hide show
  1. package/lib/cjs/presentation-testing/ContentBuilder.d.ts +87 -87
  2. package/lib/cjs/presentation-testing/ContentBuilder.js +147 -147
  3. package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
  4. package/lib/cjs/presentation-testing/Helpers.d.ts +38 -38
  5. package/lib/cjs/presentation-testing/Helpers.js +125 -125
  6. package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
  7. package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +66 -66
  8. package/lib/cjs/presentation-testing/HierarchyBuilder.js +68 -68
  9. package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -1
  10. package/lib/cjs/presentation-testing/IModelBuilder.d.ts +45 -45
  11. package/lib/cjs/presentation-testing/IModelBuilder.js +170 -170
  12. package/lib/cjs/presentation-testing/IModelBuilder.js.map +1 -1
  13. package/lib/cjs/presentation-testing/IModelTestUtility.d.ts +24 -24
  14. package/lib/cjs/presentation-testing/IModelTestUtility.js +62 -62
  15. package/lib/cjs/presentation-testing/IModelTestUtility.js.map +1 -1
  16. package/lib/cjs/presentation-testing.d.ts +28 -28
  17. package/lib/cjs/presentation-testing.js +44 -44
  18. package/lib/cjs/presentation-testing.js.map +1 -1
  19. package/lib/esm/presentation-testing/ContentBuilder.d.ts +87 -87
  20. package/lib/esm/presentation-testing/ContentBuilder.js +143 -143
  21. package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
  22. package/lib/esm/presentation-testing/Helpers.d.ts +38 -38
  23. package/lib/esm/presentation-testing/Helpers.js +100 -100
  24. package/lib/esm/presentation-testing/Helpers.js.map +1 -1
  25. package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +66 -66
  26. package/lib/esm/presentation-testing/HierarchyBuilder.js +63 -63
  27. package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -1
  28. package/lib/esm/presentation-testing/IModelBuilder.d.ts +45 -45
  29. package/lib/esm/presentation-testing/IModelBuilder.js +146 -146
  30. package/lib/esm/presentation-testing/IModelBuilder.js.map +1 -1
  31. package/lib/esm/presentation-testing/IModelTestUtility.d.ts +24 -24
  32. package/lib/esm/presentation-testing/IModelTestUtility.js +58 -58
  33. package/lib/esm/presentation-testing/IModelTestUtility.js.map +1 -1
  34. package/lib/esm/presentation-testing.d.ts +28 -28
  35. package/lib/esm/presentation-testing.js +32 -32
  36. package/lib/esm/presentation-testing.js.map +1 -1
  37. package/package.json +13 -13
@@ -1,144 +1,144 @@
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 Content
7
- */
8
- import { using } from "@itwin/core-bentley";
9
- import { QueryRowFormat } from "@itwin/core-common";
10
- import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
11
- import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
12
- import { Presentation } from "@itwin/presentation-frontend";
13
- /**
14
- * A class that constructs content from specified imodel and ruleset.
15
- * @public
16
- */
17
- export class ContentBuilder {
18
- /**
19
- * Constructor
20
- * @param iModel
21
- * @param dataProvider
22
- */
23
- constructor(props) {
24
- this._iModel = props.imodel;
25
- this._dataProvider = props.dataProvider;
26
- this._decimalPrecision = props.decimalPrecision;
27
- }
28
- async doCreateContent(rulesetId, instanceKeys, displayType) {
29
- const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
30
- dataProvider.keys = new KeySet(instanceKeys);
31
- const content = await dataProvider.getContent();
32
- if (!content)
33
- return [];
34
- const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
35
- traverseContent(accumulator, content);
36
- return accumulator.records;
37
- }
38
- /**
39
- * Create a list of property records using the supplied presentation ruleset.
40
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
41
- * @param instanceKeys Keys of instances that should be queried.
42
- * @param displayType Type of content container display. For example:
43
- * "PropertyPane", "Grid", "List" etc.
44
- */
45
- async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
46
- if (typeof rulesetOrId === "string")
47
- return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
48
- return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
49
- return this.doCreateContent(ruleset.id, instanceKeys, displayType);
50
- });
51
- }
52
- async getECClassNames() {
53
- const rows = [];
54
- for await (const row of this._iModel.query(`
55
- SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
56
- INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
57
- WHERE c.Modifier <> 1 AND c.Type = 0
58
- ORDER BY s.Name, c.Name
59
- `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
60
- rows.push(row);
61
- }
62
- return rows;
63
- }
64
- async createContentForClasses(rulesetOrId, limitInstances, displayType) {
65
- const classNameEntries = await this.getECClassNames();
66
- const contents = [];
67
- for (const nameEntry of classNameEntries) {
68
- // try {
69
- const instanceIds = [];
70
- for await (const row of this._iModel.query(`
71
- SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
72
- ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
73
- instanceIds.push(row.id);
74
- }
75
- if (!instanceIds.length)
76
- continue;
77
- const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
78
- contents.push({
79
- className: `${nameEntry.schemaName}:${nameEntry.className}`,
80
- records: await this.createContent(rulesetOrId, instanceKeys, displayType),
81
- });
82
- }
83
- return contents;
84
- }
85
- /**
86
- * Create a list of grouped property records using the supplied presentation ruleset.
87
- * Each group includes all of the class instances.
88
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
89
- * @param displayType Type of content container display. For example:
90
- * "PropertyPane", "Grid", "List" etc.
91
- */
92
- async createContentForAllInstances(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
93
- return this.createContentForClasses(rulesetOrId, false, displayType);
94
- }
95
- /**
96
- * Create a list of grouped property records using the supplied presentation ruleset.
97
- * Each group includes at most one class instance.
98
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
99
- * @param displayType Type of content container display. For example:
100
- * "PropertyPane", "Grid", "List" etc.
101
- */
102
- async createContentForInstancePerClass(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
103
- return this.createContentForClasses(rulesetOrId, true, displayType);
104
- }
105
- }
106
- class PropertyRecordsAccumulator extends PropertyRecordsBuilder {
107
- constructor(decimalPrecision) {
108
- super();
109
- this._records = [];
110
- this._decimalPrecision = decimalPrecision;
111
- }
112
- get records() {
113
- return this._records;
114
- }
115
- createRootPropertiesAppender() {
116
- return {
117
- append: (record) => {
118
- this._records.push(record.record);
119
- },
120
- };
121
- }
122
- processRawValue(value) {
123
- if (this._decimalPrecision === undefined)
124
- return value;
125
- if (typeof value === "number") {
126
- return +(Number(value)).toFixed(this._decimalPrecision);
127
- }
128
- if (Array.isArray(value)) {
129
- return value.map((item) => this.processRawValue(item));
130
- }
131
- if (value instanceof Object) {
132
- const res = {};
133
- Object.entries(value).forEach(([key, memberValue]) => {
134
- res[key] = this.processRawValue(memberValue);
135
- });
136
- return res;
137
- }
138
- return value;
139
- }
140
- processPrimitiveValue(props) {
141
- super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
142
- }
143
- }
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 Content
7
+ */
8
+ import { using } from "@itwin/core-bentley";
9
+ import { QueryRowFormat } from "@itwin/core-common";
10
+ import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
11
+ import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
12
+ import { Presentation } from "@itwin/presentation-frontend";
13
+ /**
14
+ * A class that constructs content from specified imodel and ruleset.
15
+ * @public
16
+ */
17
+ export class ContentBuilder {
18
+ /**
19
+ * Constructor
20
+ * @param iModel
21
+ * @param dataProvider
22
+ */
23
+ constructor(props) {
24
+ this._iModel = props.imodel;
25
+ this._dataProvider = props.dataProvider;
26
+ this._decimalPrecision = props.decimalPrecision;
27
+ }
28
+ async doCreateContent(rulesetId, instanceKeys, displayType) {
29
+ const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
30
+ dataProvider.keys = new KeySet(instanceKeys);
31
+ const content = await dataProvider.getContent();
32
+ if (!content)
33
+ return [];
34
+ const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
35
+ traverseContent(accumulator, content);
36
+ return accumulator.records;
37
+ }
38
+ /**
39
+ * Create a list of property records using the supplied presentation ruleset.
40
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
41
+ * @param instanceKeys Keys of instances that should be queried.
42
+ * @param displayType Type of content container display. For example:
43
+ * "PropertyPane", "Grid", "List" etc.
44
+ */
45
+ async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
46
+ if (typeof rulesetOrId === "string")
47
+ return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
48
+ return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
49
+ return this.doCreateContent(ruleset.id, instanceKeys, displayType);
50
+ });
51
+ }
52
+ async getECClassNames() {
53
+ const rows = [];
54
+ for await (const row of this._iModel.query(`
55
+ SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
56
+ INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
57
+ WHERE c.Modifier <> 1 AND c.Type = 0
58
+ ORDER BY s.Name, c.Name
59
+ `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
60
+ rows.push(row);
61
+ }
62
+ return rows;
63
+ }
64
+ async createContentForClasses(rulesetOrId, limitInstances, displayType) {
65
+ const classNameEntries = await this.getECClassNames();
66
+ const contents = [];
67
+ for (const nameEntry of classNameEntries) {
68
+ // try {
69
+ const instanceIds = [];
70
+ for await (const row of this._iModel.query(`
71
+ SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
72
+ ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
73
+ instanceIds.push(row.id);
74
+ }
75
+ if (!instanceIds.length)
76
+ continue;
77
+ const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
78
+ contents.push({
79
+ className: `${nameEntry.schemaName}:${nameEntry.className}`,
80
+ records: await this.createContent(rulesetOrId, instanceKeys, displayType),
81
+ });
82
+ }
83
+ return contents;
84
+ }
85
+ /**
86
+ * Create a list of grouped property records using the supplied presentation ruleset.
87
+ * Each group includes all of the class instances.
88
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
89
+ * @param displayType Type of content container display. For example:
90
+ * "PropertyPane", "Grid", "List" etc.
91
+ */
92
+ async createContentForAllInstances(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
93
+ return this.createContentForClasses(rulesetOrId, false, displayType);
94
+ }
95
+ /**
96
+ * Create a list of grouped property records using the supplied presentation ruleset.
97
+ * Each group includes at most one class instance.
98
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
99
+ * @param displayType Type of content container display. For example:
100
+ * "PropertyPane", "Grid", "List" etc.
101
+ */
102
+ async createContentForInstancePerClass(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
103
+ return this.createContentForClasses(rulesetOrId, true, displayType);
104
+ }
105
+ }
106
+ class PropertyRecordsAccumulator extends PropertyRecordsBuilder {
107
+ constructor(decimalPrecision) {
108
+ super();
109
+ this._records = [];
110
+ this._decimalPrecision = decimalPrecision;
111
+ }
112
+ get records() {
113
+ return this._records;
114
+ }
115
+ createRootPropertiesAppender() {
116
+ return {
117
+ append: (record) => {
118
+ this._records.push(record.record);
119
+ },
120
+ };
121
+ }
122
+ processRawValue(value) {
123
+ if (this._decimalPrecision === undefined)
124
+ return value;
125
+ if (typeof value === "number") {
126
+ return +(Number(value)).toFixed(this._decimalPrecision);
127
+ }
128
+ if (Array.isArray(value)) {
129
+ return value.map((item) => this.processRawValue(item));
130
+ }
131
+ if (value instanceof Object) {
132
+ const res = {};
133
+ Object.entries(value).forEach(([key, memberValue]) => {
134
+ res[key] = this.processRawValue(memberValue);
135
+ });
136
+ return res;
137
+ }
138
+ return value;
139
+ }
140
+ processPrimitiveValue(props) {
141
+ super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
142
+ }
143
+ }
144
144
  //# sourceMappingURL=ContentBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAG/F;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EACI,0BAA0B,EAAe,MAAM,EAAuE,eAAe,GAE/I,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAwB,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiD5D;;;GAGG;AACH,MAAM,OAAO,c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AAQ,EAAE;YAC7B,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;SACzD;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;SACxD;QAED,IAAI,KAAK,YAAY,MAAM,EAAE;YAC3B,MAAM,GAAG,GAAc,EAAE,CAAC;YAC1B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;gBACnD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;SACZ;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEe,qBAAqB,CAAC,KAAiC;QACrE,KAAK,CAAC,qBAAqB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC5F,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\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\n/** @packageDocumentation\n * @module Content\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, ProcessPrimitiveValueProps, RegisteredRuleset, Ruleset, traverseContent,\n Value, ValuesMap,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\n\n/**\n * Interface for a data provider, which is used by ContentBuilder.\n * @public\n */\nexport interface IContentBuilderDataProvider {\n /** Keys the data provider is creating content for */\n keys: Readonly<KeySet>;\n /** Get the size of content result set */\n getContentSetSize: () => Promise<number>;\n /** Get the content */\n getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;\n}\n\n/**\n * Property records grouped under a single className\n * @public\n */\nexport interface ContentBuilderResult {\n /** Full name of ECClass whose records are contained in this data structure */\n className: string;\n /** Property records for the ECClass instance */\n records: PropertyRecord[];\n}\n\n/**\n * Properties for creating a `ContentBuilder` instance.\n * @public\n */\nexport interface ContentBuilderProps {\n /** The iModel to pull data from */\n imodel: IModelConnection;\n\n /** Custom data provider that allows mocking data ContentBuilder receives */\n dataProvider?: IContentBuilderDataProvider;\n\n /**\n * Decimal precision or numeric types.\n *\n * Raw numeric values with high precision may slightly differ from platform to platform due to\n * rounding differences on different platforms. This may be a problem when used with snapshot testing,\n * in which case this attribute may be set to supply the maximum precision of raw numeric values.\n *\n * By default no rounding is applied.\n */\n decimalPrecision?: number;\n}\n\n/**\n * A class that constructs content from specified imodel and ruleset.\n * @public\n */\nexport class ContentBuilder {\n private readonly _iModel: IModelConnection;\n private _dataProvider: IContentBuilderDataProvider | undefined;\n private _decimalPrecision?: number;\n\n /**\n * Constructor\n * @param iModel\n * @param dataProvider\n */\n constructor(props: ContentBuilderProps) {\n this._iModel = props.imodel;\n this._dataProvider = props.dataProvider;\n this._decimalPrecision = props.decimalPrecision;\n }\n\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\n dataProvider.keys = new KeySet(instanceKeys);\n\n const content = await dataProvider.getContent();\n if (!content)\n return [];\n\n const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);\n traverseContent(accumulator, content);\n return accumulator.records;\n }\n\n /**\n * Create a list of property records using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param instanceKeys Keys of instances that should be queried.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\n });\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\n const rows = [];\n for await (const row of this._iModel.query(`\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\n WHERE c.Modifier <> 1 AND c.Type = 0\n ORDER BY s.Name, c.Name\n `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {\n rows.push(row);\n }\n return rows;\n }\n\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\n const classNameEntries = await this.getECClassNames();\n\n const contents: ContentBuilderResult[] = [];\n\n for (const nameEntry of classNameEntries) {\n // try {\n const instanceIds = [];\n for await (const row of this._iModel.query(`\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {\n instanceIds.push(row.id);\n }\n\n if (!instanceIds.length)\n continue;\n\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry } as InstanceKey));\n\n contents.push({\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\n });\n }\n\n return contents;\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes all of the class instances.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, false, displayType);\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes at most one class instance.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, true, displayType);\n }\n}\n\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\n private _records: PropertyRecord[] = [];\n private _decimalPrecision?: number;\n\n public constructor(decimalPrecision?: number) {\n super();\n this._decimalPrecision = decimalPrecision;\n }\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n protected createRootPropertiesAppender() {\n return {\n append: (record: FieldHierarchyRecord) => {\n this._records.push(record.record);\n },\n };\n }\n\n private processRawValue(value: Value): Value {\n if (this._decimalPrecision === undefined)\n return value;\n\n if (typeof value === \"number\") {\n return +(Number(value)).toFixed(this._decimalPrecision);\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => this.processRawValue(item));\n }\n\n if (value instanceof Object) {\n const res: ValuesMap = {};\n Object.entries(value).forEach(([key, memberValue]) => {\n res[key] = this.processRawValue(memberValue);\n });\n return res;\n }\n\n return value;\n }\n\n public override processPrimitiveValue(props: ProcessPrimitiveValueProps) {\n super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue)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AC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC5F,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\r\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\r\n/** @packageDocumentation\r\n * @module Content\r\n */\r\nimport { using } from \"@itwin/core-bentley\";\r\nimport { QueryRowFormat } from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"@itwin/core-frontend\";\r\nimport {\r\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, ProcessPrimitiveValueProps, RegisteredRuleset, Ruleset, traverseContent,\r\n Value, ValuesMap,\r\n} from \"@itwin/presentation-common\";\r\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\r\nimport { Presentation } from \"@itwin/presentation-frontend\";\r\n\r\n/**\r\n * Interface for a data provider, which is used by ContentBuilder.\r\n * @public\r\n */\r\nexport interface IContentBuilderDataProvider {\r\n /** Keys the data provider is creating content for */\r\n keys: Readonly<KeySet>;\r\n /** Get the size of content result set */\r\n getContentSetSize: () => Promise<number>;\r\n /** Get the content */\r\n getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;\r\n}\r\n\r\n/**\r\n * Property records grouped under a single className\r\n * @public\r\n */\r\nexport interface ContentBuilderResult {\r\n /** Full name of ECClass whose records are contained in this data structure */\r\n className: string;\r\n /** Property records for the ECClass instance */\r\n records: PropertyRecord[];\r\n}\r\n\r\n/**\r\n * Properties for creating a `ContentBuilder` instance.\r\n * @public\r\n */\r\nexport interface ContentBuilderProps {\r\n /** The iModel to pull data from */\r\n imodel: IModelConnection;\r\n\r\n /** Custom data provider that allows mocking data ContentBuilder receives */\r\n dataProvider?: IContentBuilderDataProvider;\r\n\r\n /**\r\n * Decimal precision or numeric types.\r\n *\r\n * Raw numeric values with high precision may slightly differ from platform to platform due to\r\n * rounding differences on different platforms. This may be a problem when used with snapshot testing,\r\n * in which case this attribute may be set to supply the maximum precision of raw numeric values.\r\n *\r\n * By default no rounding is applied.\r\n */\r\n decimalPrecision?: number;\r\n}\r\n\r\n/**\r\n * A class that constructs content from specified imodel and ruleset.\r\n * @public\r\n */\r\nexport class ContentBuilder {\r\n private readonly _iModel: IModelConnection;\r\n private _dataProvider: IContentBuilderDataProvider | undefined;\r\n private _decimalPrecision?: number;\r\n\r\n /**\r\n * Constructor\r\n * @param iModel\r\n * @param dataProvider\r\n */\r\n constructor(props: ContentBuilderProps) {\r\n this._iModel = props.imodel;\r\n this._dataProvider = props.dataProvider;\r\n this._decimalPrecision = props.decimalPrecision;\r\n }\r\n\r\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\r\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\r\n dataProvider.keys = new KeySet(instanceKeys);\r\n\r\n const content = await dataProvider.getContent();\r\n if (!content)\r\n return [];\r\n\r\n const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);\r\n traverseContent(accumulator, content);\r\n return accumulator.records;\r\n }\r\n\r\n /**\r\n * Create a list of property records using the supplied presentation ruleset.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n * @param instanceKeys Keys of instances that should be queried.\r\n * @param displayType Type of content container display. For example:\r\n * \"PropertyPane\", \"Grid\", \"List\" etc.\r\n */\r\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\r\n if (typeof rulesetOrId === \"string\")\r\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\r\n\r\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\r\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\r\n });\r\n }\r\n\r\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\r\n const rows = [];\r\n for await (const row of this._iModel.query(`\r\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\r\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\r\n WHERE c.Modifier <> 1 AND c.Type = 0\r\n ORDER BY s.Name, c.Name\r\n `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {\r\n rows.push(row);\r\n }\r\n return rows;\r\n }\r\n\r\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\r\n const classNameEntries = await this.getECClassNames();\r\n\r\n const contents: ContentBuilderResult[] = [];\r\n\r\n for (const nameEntry of classNameEntries) {\r\n // try {\r\n const instanceIds = [];\r\n for await (const row of this._iModel.query(`\r\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\r\n ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {\r\n instanceIds.push(row.id);\r\n }\r\n\r\n if (!instanceIds.length)\r\n continue;\r\n\r\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry } as InstanceKey));\r\n\r\n contents.push({\r\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\r\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\r\n });\r\n }\r\n\r\n return contents;\r\n }\r\n\r\n /**\r\n * Create a list of grouped property records using the supplied presentation ruleset.\r\n * Each group includes all of the class instances.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n * @param displayType Type of content container display. For example:\r\n * \"PropertyPane\", \"Grid\", \"List\" etc.\r\n */\r\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\r\n return this.createContentForClasses(rulesetOrId, false, displayType);\r\n }\r\n\r\n /**\r\n * Create a list of grouped property records using the supplied presentation ruleset.\r\n * Each group includes at most one class instance.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n * @param displayType Type of content container display. For example:\r\n * \"PropertyPane\", \"Grid\", \"List\" etc.\r\n */\r\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\r\n return this.createContentForClasses(rulesetOrId, true, displayType);\r\n }\r\n}\r\n\r\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\r\n private _records: PropertyRecord[] = [];\r\n private _decimalPrecision?: number;\r\n\r\n public constructor(decimalPrecision?: number) {\r\n super();\r\n this._decimalPrecision = decimalPrecision;\r\n }\r\n\r\n public get records(): PropertyRecord[] {\r\n return this._records;\r\n }\r\n\r\n protected createRootPropertiesAppender() {\r\n return {\r\n append: (record: FieldHierarchyRecord) => {\r\n this._records.push(record.record);\r\n },\r\n };\r\n }\r\n\r\n private processRawValue(value: Value): Value {\r\n if (this._decimalPrecision === undefined)\r\n return value;\r\n\r\n if (typeof value === \"number\") {\r\n return +(Number(value)).toFixed(this._decimalPrecision);\r\n }\r\n\r\n if (Array.isArray(value)) {\r\n return value.map((item) => this.processRawValue(item));\r\n }\r\n\r\n if (value instanceof Object) {\r\n const res: ValuesMap = {};\r\n Object.entries(value).forEach(([key, memberValue]) => {\r\n res[key] = this.processRawValue(memberValue);\r\n });\r\n return res;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n public override processPrimitiveValue(props: ProcessPrimitiveValueProps) {\r\n super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });\r\n }\r\n}\r\n"]}
@@ -1,39 +1,39 @@
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
- export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
6
- /** @public */
7
- export interface PresentationTestingInitProps {
8
- /** Properties for backend initialization */
9
- backendProps?: PresentationBackendProps;
10
- /** Properties for `IModelHost` */
11
- backendHostProps?: IModelHostOptions;
12
- /** Properties for frontend initialization */
13
- frontendProps?: PresentationFrontendProps;
14
- /** IModelApp implementation */
15
- frontendApp?: {
16
- startup: (opts?: IModelAppOptions) => Promise<void>;
17
- };
18
- /** `IModelApp` options */
19
- frontendAppOptions?: IModelAppOptions;
20
- }
21
- /**
22
- * Initialize the framework for presentation testing. The function sets up backend,
23
- * frontend and RPC communication between them.
24
- *
25
- * @see `terminate`
26
- *
27
- * @public
28
- */
29
- export declare const initialize: (props?: PresentationTestingInitProps | undefined) => Promise<void>;
30
- /**
31
- * Undoes the setup made by `initialize`.
32
- * @param frontendApp IModelApp implementation
33
- *
34
- * @see `initialize`
35
- *
36
- * @public
37
- */
38
- 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
+ export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
6
+ /** @public */
7
+ export interface PresentationTestingInitProps {
8
+ /** Properties for backend initialization */
9
+ backendProps?: PresentationBackendProps;
10
+ /** Properties for `IModelHost` */
11
+ backendHostProps?: IModelHostOptions;
12
+ /** Properties for frontend initialization */
13
+ frontendProps?: PresentationFrontendProps;
14
+ /** IModelApp implementation */
15
+ frontendApp?: {
16
+ startup: (opts?: IModelAppOptions) => Promise<void>;
17
+ };
18
+ /** `IModelApp` options */
19
+ frontendAppOptions?: IModelAppOptions;
20
+ }
21
+ /**
22
+ * Initialize the framework for presentation testing. The function sets up backend,
23
+ * frontend and RPC communication between them.
24
+ *
25
+ * @see `terminate`
26
+ *
27
+ * @public
28
+ */
29
+ export declare const initialize: (props?: PresentationTestingInitProps | undefined) => Promise<void>;
30
+ /**
31
+ * Undoes the setup made by `initialize`.
32
+ * @param frontendApp IModelApp implementation
33
+ *
34
+ * @see `initialize`
35
+ *
36
+ * @public
37
+ */
38
+ export declare const terminate: (frontendApp?: typeof IModelApp) => Promise<void>;
39
39
  //# sourceMappingURL=Helpers.d.ts.map
@@ -1,101 +1,101 @@
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
- import { join } from "path";
9
- import * as rimraf from "rimraf";
10
- import { IModelHost } from "@itwin/core-backend";
11
- import { Guid } from "@itwin/core-bentley";
12
- import { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, SnapshotIModelRpcInterface, } from "@itwin/core-common";
13
- import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
14
- import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerMode, } from "@itwin/presentation-backend";
15
- import { PresentationRpcInterface } from "@itwin/presentation-common";
16
- import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
17
- function initializeRpcInterfaces(interfaces) {
18
- const config = class extends RpcDefaultConfiguration {
19
- constructor() {
20
- super(...arguments);
21
- this.interfaces = () => interfaces;
22
- }
23
- };
24
- for (const definition of interfaces)
25
- RpcConfiguration.assign(definition, () => config);
26
- const instance = RpcConfiguration.obtain(config);
27
- try {
28
- RpcConfiguration.initializeInterfaces(instance);
29
- }
30
- catch {
31
- // this may fail with "Error: RPC interface "xxx" is already initialized." because
32
- // multiple different tests want to set up rpc interfaces
33
- }
34
- }
35
- let isInitialized = false;
36
- export { HierarchyCacheMode, PresentationManagerMode };
37
- /**
38
- * Initialize the framework for presentation testing. The function sets up backend,
39
- * frontend and RPC communication between them.
40
- *
41
- * @see `terminate`
42
- *
43
- * @public
44
- */
45
- export const initialize = async (props) => {
46
- var _a;
47
- if (isInitialized)
48
- return;
49
- if (!props)
50
- props = {};
51
- // set up rpc interfaces
52
- initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
53
- // init backend
54
- // make sure backend gets assigned an id which puts its resources into a unique directory
55
- props.backendProps = (_a = props.backendProps) !== null && _a !== void 0 ? _a : {};
56
- if (!props.backendProps.id)
57
- props.backendProps.id = `test-${Guid.createValue()}`;
58
- await IModelHost.startup({ cacheDir: join(__dirname, ".cache"), ...props.backendHostProps });
59
- PresentationBackend.initialize(props.backendProps);
60
- // init frontend
61
- if (!props.frontendApp)
62
- props.frontendApp = NoRenderApp;
63
- await props.frontendApp.startup(props.frontendAppOptions);
64
- const defaultFrontendProps = {
65
- presentation: {
66
- activeLocale: IModelApp.localization.getLanguageList()[0],
67
- },
68
- };
69
- await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });
70
- isInitialized = true;
71
- };
72
- /**
73
- * Undoes the setup made by `initialize`.
74
- * @param frontendApp IModelApp implementation
75
- *
76
- * @see `initialize`
77
- *
78
- * @public
79
- */
80
- export const terminate = async (frontendApp = IModelApp) => {
81
- var _a, _b, _c;
82
- if (!isInitialized)
83
- return;
84
- // store directory that needs to be cleaned-up
85
- let hierarchiesCacheDirectory;
86
- const hierarchiesCacheConfig = (_b = (_a = PresentationBackend.initProps) === null || _a === void 0 ? void 0 : _a.caching) === null || _b === void 0 ? void 0 : _b.hierarchies;
87
- if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Disk)
88
- hierarchiesCacheDirectory = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.directory;
89
- else if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Hybrid)
90
- hierarchiesCacheDirectory = (_c = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.disk) === null || _c === void 0 ? void 0 : _c.directory;
91
- // terminate backend
92
- PresentationBackend.terminate();
93
- await IModelHost.shutdown();
94
- if (hierarchiesCacheDirectory)
95
- rimraf.sync(hierarchiesCacheDirectory);
96
- // terminate frontend
97
- PresentationFrontend.terminate();
98
- await frontendApp.shutdown();
99
- isInitialized = false;
100
- };
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
+ import { join } from "path";
9
+ import * as rimraf from "rimraf";
10
+ import { IModelHost } from "@itwin/core-backend";
11
+ import { Guid } from "@itwin/core-bentley";
12
+ import { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, SnapshotIModelRpcInterface, } from "@itwin/core-common";
13
+ import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
14
+ import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerMode, } from "@itwin/presentation-backend";
15
+ import { PresentationRpcInterface } from "@itwin/presentation-common";
16
+ import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
17
+ function initializeRpcInterfaces(interfaces) {
18
+ const config = class extends RpcDefaultConfiguration {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.interfaces = () => interfaces;
22
+ }
23
+ };
24
+ for (const definition of interfaces)
25
+ RpcConfiguration.assign(definition, () => config);
26
+ const instance = RpcConfiguration.obtain(config);
27
+ try {
28
+ RpcConfiguration.initializeInterfaces(instance);
29
+ }
30
+ catch {
31
+ // this may fail with "Error: RPC interface "xxx" is already initialized." because
32
+ // multiple different tests want to set up rpc interfaces
33
+ }
34
+ }
35
+ let isInitialized = false;
36
+ export { HierarchyCacheMode, PresentationManagerMode };
37
+ /**
38
+ * Initialize the framework for presentation testing. The function sets up backend,
39
+ * frontend and RPC communication between them.
40
+ *
41
+ * @see `terminate`
42
+ *
43
+ * @public
44
+ */
45
+ export const initialize = async (props) => {
46
+ var _a;
47
+ if (isInitialized)
48
+ return;
49
+ if (!props)
50
+ props = {};
51
+ // set up rpc interfaces
52
+ initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
53
+ // init backend
54
+ // make sure backend gets assigned an id which puts its resources into a unique directory
55
+ props.backendProps = (_a = props.backendProps) !== null && _a !== void 0 ? _a : {};
56
+ if (!props.backendProps.id)
57
+ props.backendProps.id = `test-${Guid.createValue()}`;
58
+ await IModelHost.startup({ cacheDir: join(__dirname, ".cache"), ...props.backendHostProps });
59
+ PresentationBackend.initialize(props.backendProps);
60
+ // init frontend
61
+ if (!props.frontendApp)
62
+ props.frontendApp = NoRenderApp;
63
+ await props.frontendApp.startup(props.frontendAppOptions);
64
+ const defaultFrontendProps = {
65
+ presentation: {
66
+ activeLocale: IModelApp.localization.getLanguageList()[0],
67
+ },
68
+ };
69
+ await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });
70
+ isInitialized = true;
71
+ };
72
+ /**
73
+ * Undoes the setup made by `initialize`.
74
+ * @param frontendApp IModelApp implementation
75
+ *
76
+ * @see `initialize`
77
+ *
78
+ * @public
79
+ */
80
+ export const terminate = async (frontendApp = IModelApp) => {
81
+ var _a, _b, _c;
82
+ if (!isInitialized)
83
+ return;
84
+ // store directory that needs to be cleaned-up
85
+ let hierarchiesCacheDirectory;
86
+ const hierarchiesCacheConfig = (_b = (_a = PresentationBackend.initProps) === null || _a === void 0 ? void 0 : _a.caching) === null || _b === void 0 ? void 0 : _b.hierarchies;
87
+ if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Disk)
88
+ hierarchiesCacheDirectory = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.directory;
89
+ else if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Hybrid)
90
+ hierarchiesCacheDirectory = (_c = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.disk) === null || _c === void 0 ? void 0 : _c.directory;
91
+ // terminate backend
92
+ PresentationBackend.terminate();
93
+ await IModelHost.shutdown();
94
+ if (hierarchiesCacheDirectory)
95
+ rimraf.sync(hierarchiesCacheDirectory);
96
+ // terminate frontend
97
+ PresentationFrontend.terminate();
98
+ await frontendApp.shutdown();
99
+ isInitialized = false;
100
+ };
101
101
  //# sourceMappingURL=Helpers.js.map