@itwin/presentation-testing 4.0.0-dev.7 → 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
package/LICENSE.md CHANGED
@@ -1,9 +1,9 @@
1
- # MIT License
2
-
3
- Copyright © 2017-2023 Bentley Systems, Incorporated. All rights reserved.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ # MIT License
2
+
3
+ Copyright © 2017-2022 Bentley Systems, Incorporated. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # @itwin/presentation-testing
2
-
3
- Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.
4
-
5
- ## Description
6
-
7
- The __@itwin/presentation-testing__ package contains helper classes and APIs that help test presentation modules.
1
+ # @itwin/presentation-testing
2
+
3
+ Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.
4
+
5
+ ## Description
6
+
7
+ The __@itwin/presentation-testing__ package contains helper classes and APIs that help test presentation modules.
@@ -1,90 +1,93 @@
1
- import { PropertyRecord } from "@itwin/appui-abstract";
2
- import { IModelConnection } from "@itwin/core-frontend";
3
- import { Content, InstanceKey, KeySet, PageOptions, Ruleset } from "@itwin/presentation-common";
4
- /**
5
- * Interface for a data provider, which is used by ContentBuilder.
6
- * @public
7
- */
8
- export interface IContentBuilderDataProvider {
9
- /** Keys the data provider is creating content for */
10
- keys: Readonly<KeySet>;
11
- /** Get the size of content result set */
12
- getContentSetSize: () => Promise<number>;
13
- /** Get the content */
14
- getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;
15
- }
16
- /**
17
- * Property records grouped under a single className
18
- * @public
19
- */
20
- export interface ContentBuilderResult {
21
- /** Full name of ECClass whose records are contained in this data structure */
22
- className: string;
23
- /** Property records for the ECClass instance */
24
- records: PropertyRecord[];
25
- }
26
- /**
27
- * Properties for creating a `ContentBuilder` instance.
28
- * @public
29
- */
30
- export interface ContentBuilderProps {
31
- /** The iModel to pull data from */
32
- imodel: IModelConnection;
33
- /** Custom data provider that allows mocking data ContentBuilder receives */
34
- dataProvider?: IContentBuilderDataProvider;
35
- /**
36
- * Decimal precision or numeric types.
37
- *
38
- * Raw numeric values with high precision may slightly differ from platform to platform due to
39
- * rounding differences on different platforms. This may be a problem when used with snapshot testing,
40
- * in which case this attribute may be set to supply the maximum precision of raw numeric values.
41
- *
42
- * By default no rounding is applied.
43
- */
44
- decimalPrecision?: number;
45
- }
46
- /**
47
- * A class that constructs content from specified imodel and ruleset.
48
- * @public
49
- */
50
- export declare class ContentBuilder {
51
- private readonly _iModel;
52
- private _dataProvider;
53
- private _decimalPrecision?;
54
- /**
55
- * Constructor
56
- * @param iModel
57
- * @param dataProvider
58
- */
59
- constructor(props: ContentBuilderProps);
60
- private doCreateContent;
61
- /**
62
- * Create a list of property records using the supplied presentation ruleset.
63
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
64
- * @param instanceKeys Keys of instances that should be queried.
65
- * @param displayType Type of content container display. For example:
66
- * "PropertyPane", "Grid", "List" etc.
67
- */
68
- createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType?: string): Promise<PropertyRecord[]>;
69
- private getECClassNames;
70
- private createContentForClasses;
71
- /**
72
- * Create a list of grouped property records using the supplied presentation ruleset.
73
- * Each group includes all of the class instances.
74
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
75
- * @param displayType Type of content container display. For example:
76
- * "PropertyPane", "Grid", "List" etc.
77
- * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
78
- */
79
- createContentForAllInstances(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
80
- /**
81
- * Create a list of grouped property records using the supplied presentation ruleset.
82
- * Each group includes at most one class instance.
83
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
84
- * @param displayType Type of content container display. For example:
85
- * "PropertyPane", "Grid", "List" etc.
86
- * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
87
- */
88
- createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
89
- }
1
+ /** @packageDocumentation
2
+ * @module Content
3
+ */
4
+ import { PropertyRecord } from "@itwin/appui-abstract";
5
+ import { IModelConnection } from "@itwin/core-frontend";
6
+ import { Content, InstanceKey, KeySet, PageOptions, Ruleset } from "@itwin/presentation-common";
7
+ /**
8
+ * Interface for a data provider, which is used by ContentBuilder.
9
+ * @public
10
+ */
11
+ export interface IContentBuilderDataProvider {
12
+ /** Keys the data provider is creating content for */
13
+ keys: Readonly<KeySet>;
14
+ /** Get the size of content result set */
15
+ getContentSetSize: () => Promise<number>;
16
+ /** Get the content */
17
+ getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;
18
+ }
19
+ /**
20
+ * Property records grouped under a single className
21
+ * @public
22
+ */
23
+ export interface ContentBuilderResult {
24
+ /** Full name of ECClass whose records are contained in this data structure */
25
+ className: string;
26
+ /** Property records for the ECClass instance */
27
+ records: PropertyRecord[];
28
+ }
29
+ /**
30
+ * Properties for creating a `ContentBuilder` instance.
31
+ * @public
32
+ */
33
+ export interface ContentBuilderProps {
34
+ /** The iModel to pull data from */
35
+ imodel: IModelConnection;
36
+ /** Custom data provider that allows mocking data ContentBuilder receives */
37
+ dataProvider?: IContentBuilderDataProvider;
38
+ /**
39
+ * Decimal precision or numeric types.
40
+ *
41
+ * Raw numeric values with high precision may slightly differ from platform to platform due to
42
+ * rounding differences on different platforms. This may be a problem when used with snapshot testing,
43
+ * in which case this attribute may be set to supply the maximum precision of raw numeric values.
44
+ *
45
+ * By default no rounding is applied.
46
+ */
47
+ decimalPrecision?: number;
48
+ }
49
+ /**
50
+ * A class that constructs content from specified imodel and ruleset.
51
+ * @public
52
+ */
53
+ export declare class ContentBuilder {
54
+ private readonly _iModel;
55
+ private _dataProvider;
56
+ private _decimalPrecision?;
57
+ /**
58
+ * Constructor
59
+ * @param iModel
60
+ * @param dataProvider
61
+ */
62
+ constructor(props: ContentBuilderProps);
63
+ private doCreateContent;
64
+ /**
65
+ * Create a list of property records using the supplied presentation ruleset.
66
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
67
+ * @param instanceKeys Keys of instances that should be queried.
68
+ * @param displayType Type of content container display. For example:
69
+ * "PropertyPane", "Grid", "List" etc.
70
+ */
71
+ createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType?: string): Promise<PropertyRecord[]>;
72
+ private getECClassNames;
73
+ private createContentForClasses;
74
+ /**
75
+ * Create a list of grouped property records using the supplied presentation ruleset.
76
+ * Each group includes all of the class instances.
77
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
78
+ * @param displayType Type of content container display. For example:
79
+ * "PropertyPane", "Grid", "List" etc.
80
+ * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
81
+ */
82
+ createContentForAllInstances(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
83
+ /**
84
+ * Create a list of grouped property records using the supplied presentation ruleset.
85
+ * Each group includes at most one class instance.
86
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
87
+ * @param displayType Type of content container display. For example:
88
+ * "PropertyPane", "Grid", "List" etc.
89
+ * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
90
+ */
91
+ createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
92
+ }
90
93
  //# sourceMappingURL=ContentBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAMvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,OAAO,EAA8B,WAAW,EAAE,MAAM,EAAE,WAAW,EAAiD,OAAO,EAE9H,MAAM,4BAA4B,CAAC;AAIpC;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,qDAAqD;IACrD,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,yCAAyC;IACzC,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,sBAAsB;IACtB,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CAC/E;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IAEzB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,2BAA2B,CAAC;IAE3C;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,iBAAiB,CAAC,CAAS;IAEnC;;;;OAIG;gBACS,KAAK,EAAE,mBAAmB;YAMxB,eAAe;IAa7B;;;;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,WAAW,GAAE,MAAgD;YAStI,eAAe;YAaf,uBAAuB;IA4BrC;;;;;;;OAOG;IACU,4BAA4B,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;IAItI;;;;;;;OAOG;IACU,gCAAgC,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;CAG3I"}
1
+ {"version":3,"file":"ContentBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,OAAO,EAA8B,WAAW,EAAE,MAAM,EAAE,WAAW,EAAiD,OAAO,EAE9H,MAAM,4BAA4B,CAAC;AAIpC;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,qDAAqD;IACrD,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,yCAAyC;IACzC,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,sBAAsB;IACtB,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CAC/E;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IAEzB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,2BAA2B,CAAC;IAE3C;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,iBAAiB,CAAC,CAAS;IAEnC;;;;OAIG;gBACS,KAAK,EAAE,mBAAmB;YAMxB,eAAe;IAa7B;;;;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,WAAW,GAAE,MAAgD;YAStI,eAAe;YAaf,uBAAuB;IA4BrC;;;;;;;OAOG;IACU,4BAA4B,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;IAItI;;;;;;;OAOG;IACU,gCAAgC,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;CAG3I"}
@@ -1,150 +1,179 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ContentBuilder = void 0;
8
- /** @packageDocumentation
9
- * @module Content
10
- */
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_common_1 = require("@itwin/core-common");
13
- const presentation_common_1 = require("@itwin/presentation-common");
14
- const presentation_components_1 = require("@itwin/presentation-components");
15
- const presentation_frontend_1 = require("@itwin/presentation-frontend");
16
- /**
17
- * A class that constructs content from specified imodel and ruleset.
18
- * @public
19
- */
20
- class ContentBuilder {
21
- /**
22
- * Constructor
23
- * @param iModel
24
- * @param dataProvider
25
- */
26
- constructor(props) {
27
- this._iModel = props.imodel;
28
- this._dataProvider = props.dataProvider;
29
- this._decimalPrecision = props.decimalPrecision;
30
- }
31
- async doCreateContent(rulesetId, instanceKeys, displayType) {
32
- const dataProvider = this._dataProvider ? this._dataProvider : new presentation_components_1.ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
33
- dataProvider.keys = new presentation_common_1.KeySet(instanceKeys);
34
- const content = await dataProvider.getContent();
35
- if (!content)
36
- return [];
37
- const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
38
- (0, presentation_common_1.traverseContent)(accumulator, content);
39
- return accumulator.records;
40
- }
41
- /**
42
- * Create a list of property records using the supplied presentation ruleset.
43
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
44
- * @param instanceKeys Keys of instances that should be queried.
45
- * @param displayType Type of content container display. For example:
46
- * "PropertyPane", "Grid", "List" etc.
47
- */
48
- async createContent(rulesetOrId, instanceKeys, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
49
- if (typeof rulesetOrId === "string")
50
- return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
51
- return (0, core_bentley_1.using)(await presentation_frontend_1.Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
52
- return this.doCreateContent(ruleset.id, instanceKeys, displayType);
53
- });
54
- }
55
- async getECClassNames() {
56
- const rows = [];
57
- for await (const row of this._iModel.query(`
58
- SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
59
- INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
60
- WHERE c.Modifier <> 1 AND c.Type = 0
61
- ORDER BY s.Name, c.Name
62
- `, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames })) {
63
- rows.push(row);
64
- }
65
- return rows;
66
- }
67
- async createContentForClasses(rulesetOrId, limitInstances, displayType) {
68
- const classNameEntries = await this.getECClassNames();
69
- const contents = [];
70
- for (const nameEntry of classNameEntries) {
71
- // try {
72
- const instanceIds = [];
73
- for await (const row of this._iModel.query(`
74
- SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
75
- ORDER BY ECInstanceId`, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
76
- instanceIds.push(row.id);
77
- }
78
- if (!instanceIds.length)
79
- continue;
80
- const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
81
- contents.push({
82
- className: `${nameEntry.schemaName}:${nameEntry.className}`,
83
- records: await this.createContent(rulesetOrId, instanceKeys, displayType),
84
- });
85
- }
86
- return contents;
87
- }
88
- /**
89
- * Create a list of grouped property records using the supplied presentation ruleset.
90
- * Each group includes all of the class instances.
91
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
92
- * @param displayType Type of content container display. For example:
93
- * "PropertyPane", "Grid", "List" etc.
94
- * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
95
- */
96
- async createContentForAllInstances(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
97
- return this.createContentForClasses(rulesetOrId, false, displayType);
98
- }
99
- /**
100
- * Create a list of grouped property records using the supplied presentation ruleset.
101
- * Each group includes at most one class instance.
102
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
103
- * @param displayType Type of content container display. For example:
104
- * "PropertyPane", "Grid", "List" etc.
105
- * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
106
- */
107
- async createContentForInstancePerClass(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
108
- return this.createContentForClasses(rulesetOrId, true, displayType);
109
- }
110
- }
111
- exports.ContentBuilder = ContentBuilder;
112
- class PropertyRecordsAccumulator extends presentation_components_1.PropertyRecordsBuilder {
113
- constructor(decimalPrecision) {
114
- super();
115
- this._records = [];
116
- this._decimalPrecision = decimalPrecision;
117
- }
118
- get records() {
119
- return this._records;
120
- }
121
- createRootPropertiesAppender() {
122
- return {
123
- append: (record) => {
124
- this._records.push(record.record);
125
- },
126
- };
127
- }
128
- processRawValue(value) {
129
- if (this._decimalPrecision === undefined)
130
- return value;
131
- if (typeof value === "number") {
132
- return +(Number(value)).toFixed(this._decimalPrecision);
133
- }
134
- if (Array.isArray(value)) {
135
- return value.map((item) => this.processRawValue(item));
136
- }
137
- if (value instanceof Object) {
138
- const res = {};
139
- Object.entries(value).forEach(([key, memberValue]) => {
140
- res[key] = this.processRawValue(memberValue);
141
- });
142
- return res;
143
- }
144
- return value;
145
- }
146
- processPrimitiveValue(props) {
147
- super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
148
- }
149
- }
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Content
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ContentBuilder = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const presentation_common_1 = require("@itwin/presentation-common");
14
+ const presentation_components_1 = require("@itwin/presentation-components");
15
+ const presentation_frontend_1 = require("@itwin/presentation-frontend");
16
+ /**
17
+ * A class that constructs content from specified imodel and ruleset.
18
+ * @public
19
+ */
20
+ class ContentBuilder {
21
+ /**
22
+ * Constructor
23
+ * @param iModel
24
+ * @param dataProvider
25
+ */
26
+ constructor(props) {
27
+ Object.defineProperty(this, "_iModel", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "_dataProvider", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "_decimalPrecision", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ this._iModel = props.imodel;
46
+ this._dataProvider = props.dataProvider;
47
+ this._decimalPrecision = props.decimalPrecision;
48
+ }
49
+ async doCreateContent(rulesetId, instanceKeys, displayType) {
50
+ const dataProvider = this._dataProvider ? this._dataProvider : new presentation_components_1.ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
51
+ dataProvider.keys = new presentation_common_1.KeySet(instanceKeys);
52
+ const content = await dataProvider.getContent();
53
+ if (!content)
54
+ return [];
55
+ const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
56
+ (0, presentation_common_1.traverseContent)(accumulator, content);
57
+ return accumulator.records;
58
+ }
59
+ /**
60
+ * Create a list of property records using the supplied presentation ruleset.
61
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
62
+ * @param instanceKeys Keys of instances that should be queried.
63
+ * @param displayType Type of content container display. For example:
64
+ * "PropertyPane", "Grid", "List" etc.
65
+ */
66
+ async createContent(rulesetOrId, instanceKeys, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
67
+ if (typeof rulesetOrId === "string")
68
+ return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
69
+ return (0, core_bentley_1.using)(await presentation_frontend_1.Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
70
+ return this.doCreateContent(ruleset.id, instanceKeys, displayType);
71
+ });
72
+ }
73
+ async getECClassNames() {
74
+ const rows = [];
75
+ for await (const row of this._iModel.query(`
76
+ SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
77
+ INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
78
+ WHERE c.Modifier <> 1 AND c.Type = 0
79
+ ORDER BY s.Name, c.Name
80
+ `, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames })) {
81
+ rows.push(row);
82
+ }
83
+ return rows;
84
+ }
85
+ async createContentForClasses(rulesetOrId, limitInstances, displayType) {
86
+ const classNameEntries = await this.getECClassNames();
87
+ const contents = [];
88
+ for (const nameEntry of classNameEntries) {
89
+ // try {
90
+ const instanceIds = [];
91
+ for await (const row of this._iModel.query(`
92
+ SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
93
+ ORDER BY ECInstanceId`, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
94
+ instanceIds.push(row.id);
95
+ }
96
+ if (!instanceIds.length)
97
+ continue;
98
+ const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
99
+ contents.push({
100
+ className: `${nameEntry.schemaName}:${nameEntry.className}`,
101
+ records: await this.createContent(rulesetOrId, instanceKeys, displayType),
102
+ });
103
+ }
104
+ return contents;
105
+ }
106
+ /**
107
+ * Create a list of grouped property records using the supplied presentation ruleset.
108
+ * Each group includes all of the class instances.
109
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
110
+ * @param displayType Type of content container display. For example:
111
+ * "PropertyPane", "Grid", "List" etc.
112
+ * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
113
+ */
114
+ async createContentForAllInstances(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
115
+ return this.createContentForClasses(rulesetOrId, false, displayType);
116
+ }
117
+ /**
118
+ * Create a list of grouped property records using the supplied presentation ruleset.
119
+ * Each group includes at most one class instance.
120
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
121
+ * @param displayType Type of content container display. For example:
122
+ * "PropertyPane", "Grid", "List" etc.
123
+ * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
124
+ */
125
+ async createContentForInstancePerClass(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
126
+ return this.createContentForClasses(rulesetOrId, true, displayType);
127
+ }
128
+ }
129
+ exports.ContentBuilder = ContentBuilder;
130
+ class PropertyRecordsAccumulator extends presentation_components_1.PropertyRecordsBuilder {
131
+ constructor(decimalPrecision) {
132
+ super();
133
+ Object.defineProperty(this, "_records", {
134
+ enumerable: true,
135
+ configurable: true,
136
+ writable: true,
137
+ value: []
138
+ });
139
+ Object.defineProperty(this, "_decimalPrecision", {
140
+ enumerable: true,
141
+ configurable: true,
142
+ writable: true,
143
+ value: void 0
144
+ });
145
+ this._decimalPrecision = decimalPrecision;
146
+ }
147
+ get records() {
148
+ return this._records;
149
+ }
150
+ createRootPropertiesAppender() {
151
+ return {
152
+ append: (record) => {
153
+ this._records.push(record.record);
154
+ },
155
+ };
156
+ }
157
+ processRawValue(value) {
158
+ if (this._decimalPrecision === undefined)
159
+ return value;
160
+ if (typeof value === "number") {
161
+ return +(Number(value)).toFixed(this._decimalPrecision);
162
+ }
163
+ if (Array.isArray(value)) {
164
+ return value.map((item) => this.processRawValue(item));
165
+ }
166
+ if (value instanceof Object) {
167
+ const res = {};
168
+ Object.entries(value).forEach(([key, memberValue]) => {
169
+ res[key] = this.processRawValue(memberValue);
170
+ });
171
+ return res;
172
+ }
173
+ return value;
174
+ }
175
+ processPrimitiveValue(props) {
176
+ super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
177
+ }
178
+ }
150
179
  //# sourceMappingURL=ContentBuilder.js.map