@itwin/presentation-testing 3.8.0-dev.1 → 3.8.0

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 (32) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/cjs/presentation-testing/ContentBuilder.d.ts +89 -89
  3. package/lib/cjs/presentation-testing/ContentBuilder.js +151 -151
  4. package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
  5. package/lib/cjs/presentation-testing/Helpers.d.ts +42 -42
  6. package/lib/cjs/presentation-testing/Helpers.js +139 -139
  7. package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
  8. package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +66 -66
  9. package/lib/cjs/presentation-testing/HierarchyBuilder.js +67 -67
  10. package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -1
  11. package/lib/cjs/presentation-testing/IModelUtilities.d.ts +46 -46
  12. package/lib/cjs/presentation-testing/IModelUtilities.js +77 -77
  13. package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -1
  14. package/lib/cjs/presentation-testing.d.ts +28 -28
  15. package/lib/cjs/presentation-testing.js +44 -44
  16. package/lib/cjs/presentation-testing.js.map +1 -1
  17. package/lib/esm/presentation-testing/ContentBuilder.d.ts +89 -89
  18. package/lib/esm/presentation-testing/ContentBuilder.js +147 -147
  19. package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
  20. package/lib/esm/presentation-testing/Helpers.d.ts +42 -42
  21. package/lib/esm/presentation-testing/Helpers.js +114 -114
  22. package/lib/esm/presentation-testing/Helpers.js.map +1 -1
  23. package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +66 -66
  24. package/lib/esm/presentation-testing/HierarchyBuilder.js +62 -62
  25. package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -1
  26. package/lib/esm/presentation-testing/IModelUtilities.d.ts +46 -46
  27. package/lib/esm/presentation-testing/IModelUtilities.js +69 -69
  28. package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -1
  29. package/lib/esm/presentation-testing.d.ts +28 -28
  30. package/lib/esm/presentation-testing.js +32 -32
  31. package/lib/esm/presentation-testing.js.map +1 -1
  32. package/package.json +13 -13
package/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Change Log - @itwin/presentation-testing
2
2
 
3
- This log was last generated on Mon, 20 Nov 2023 18:24:24 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 08 Dec 2023 15:23:59 GMT and should not be manually modified.
4
+
5
+ ## 3.8.0
6
+ Fri, 08 Dec 2023 15:23:59 GMT
7
+
8
+ _Version update only_
4
9
 
5
10
  ## 3.7.17
6
11
  Mon, 20 Nov 2023 18:24:24 GMT
@@ -1,90 +1,90 @@
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
+ 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
+ }
90
90
  //# sourceMappingURL=ContentBuilder.d.ts.map
@@ -1,152 +1,152 @@
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
- // eslint-disable-next-line deprecation/deprecation
58
- for await (const row of this._iModel.query(`
59
- SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
60
- INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
61
- WHERE c.Modifier <> 1 AND c.Type = 0
62
- ORDER BY s.Name, c.Name
63
- `, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames })) {
64
- rows.push(row);
65
- }
66
- return rows;
67
- }
68
- async createContentForClasses(rulesetOrId, limitInstances, displayType) {
69
- const classNameEntries = await this.getECClassNames();
70
- const contents = [];
71
- for (const nameEntry of classNameEntries) {
72
- // try {
73
- const instanceIds = [];
74
- // eslint-disable-next-line deprecation/deprecation
75
- for await (const row of this._iModel.query(`
76
- SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
77
- ORDER BY ECInstanceId`, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
78
- instanceIds.push(row.id);
79
- }
80
- if (!instanceIds.length)
81
- continue;
82
- const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
83
- contents.push({
84
- className: `${nameEntry.schemaName}:${nameEntry.className}`,
85
- records: await this.createContent(rulesetOrId, instanceKeys, displayType),
86
- });
87
- }
88
- return contents;
89
- }
90
- /**
91
- * Create a list of grouped property records using the supplied presentation ruleset.
92
- * Each group includes all of the class instances.
93
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
94
- * @param displayType Type of content container display. For example:
95
- * "PropertyPane", "Grid", "List" etc.
96
- * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
97
- */
98
- async createContentForAllInstances(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
99
- return this.createContentForClasses(rulesetOrId, false, displayType);
100
- }
101
- /**
102
- * Create a list of grouped property records using the supplied presentation ruleset.
103
- * Each group includes at most one class instance.
104
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
105
- * @param displayType Type of content container display. For example:
106
- * "PropertyPane", "Grid", "List" etc.
107
- * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
108
- */
109
- async createContentForInstancePerClass(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
110
- return this.createContentForClasses(rulesetOrId, true, displayType);
111
- }
112
- }
113
- exports.ContentBuilder = ContentBuilder;
114
- class PropertyRecordsAccumulator extends presentation_components_1.PropertyRecordsBuilder {
115
- constructor(decimalPrecision) {
116
- super();
117
- this._records = [];
118
- this._decimalPrecision = decimalPrecision;
119
- }
120
- get records() {
121
- return this._records;
122
- }
123
- createRootPropertiesAppender() {
124
- return {
125
- append: (record) => {
126
- this._records.push(record.record);
127
- },
128
- };
129
- }
130
- processRawValue(value) {
131
- if (this._decimalPrecision === undefined)
132
- return value;
133
- if (typeof value === "number") {
134
- return +(Number(value)).toFixed(this._decimalPrecision);
135
- }
136
- if (Array.isArray(value)) {
137
- return value.map((item) => this.processRawValue(item));
138
- }
139
- if (value instanceof Object) {
140
- const res = {};
141
- Object.entries(value).forEach(([key, memberValue]) => {
142
- res[key] = this.processRawValue(memberValue);
143
- });
144
- return res;
145
- }
146
- return value;
147
- }
148
- processPrimitiveValue(props) {
149
- super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
150
- }
151
- }
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
+ // eslint-disable-next-line deprecation/deprecation
58
+ for await (const row of this._iModel.query(`
59
+ SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
60
+ INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
61
+ WHERE c.Modifier <> 1 AND c.Type = 0
62
+ ORDER BY s.Name, c.Name
63
+ `, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames })) {
64
+ rows.push(row);
65
+ }
66
+ return rows;
67
+ }
68
+ async createContentForClasses(rulesetOrId, limitInstances, displayType) {
69
+ const classNameEntries = await this.getECClassNames();
70
+ const contents = [];
71
+ for (const nameEntry of classNameEntries) {
72
+ // try {
73
+ const instanceIds = [];
74
+ // eslint-disable-next-line deprecation/deprecation
75
+ for await (const row of this._iModel.query(`
76
+ SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
77
+ ORDER BY ECInstanceId`, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
78
+ instanceIds.push(row.id);
79
+ }
80
+ if (!instanceIds.length)
81
+ continue;
82
+ const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
83
+ contents.push({
84
+ className: `${nameEntry.schemaName}:${nameEntry.className}`,
85
+ records: await this.createContent(rulesetOrId, instanceKeys, displayType),
86
+ });
87
+ }
88
+ return contents;
89
+ }
90
+ /**
91
+ * Create a list of grouped property records using the supplied presentation ruleset.
92
+ * Each group includes all of the class instances.
93
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
94
+ * @param displayType Type of content container display. For example:
95
+ * "PropertyPane", "Grid", "List" etc.
96
+ * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
97
+ */
98
+ async createContentForAllInstances(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
99
+ return this.createContentForClasses(rulesetOrId, false, displayType);
100
+ }
101
+ /**
102
+ * Create a list of grouped property records using the supplied presentation ruleset.
103
+ * Each group includes at most one class instance.
104
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
105
+ * @param displayType Type of content container display. For example:
106
+ * "PropertyPane", "Grid", "List" etc.
107
+ * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
108
+ */
109
+ async createContentForInstancePerClass(rulesetOrId, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
110
+ return this.createContentForClasses(rulesetOrId, true, displayType);
111
+ }
112
+ }
113
+ exports.ContentBuilder = ContentBuilder;
114
+ class PropertyRecordsAccumulator extends presentation_components_1.PropertyRecordsBuilder {
115
+ constructor(decimalPrecision) {
116
+ super();
117
+ this._records = [];
118
+ this._decimalPrecision = decimalPrecision;
119
+ }
120
+ get records() {
121
+ return this._records;
122
+ }
123
+ createRootPropertiesAppender() {
124
+ return {
125
+ append: (record) => {
126
+ this._records.push(record.record);
127
+ },
128
+ };
129
+ }
130
+ processRawValue(value) {
131
+ if (this._decimalPrecision === undefined)
132
+ return value;
133
+ if (typeof value === "number") {
134
+ return +(Number(value)).toFixed(this._decimalPrecision);
135
+ }
136
+ if (Array.isArray(value)) {
137
+ return value.map((item) => this.processRawValue(item));
138
+ }
139
+ if (value instanceof Object) {
140
+ const res = {};
141
+ Object.entries(value).forEach(([key, memberValue]) => {
142
+ res[key] = this.processRawValue(memberValue);
143
+ });
144
+ return res;
145
+ }
146
+ return value;
147
+ }
148
+ processPrimitiveValue(props) {
149
+ super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
150
+ }
151
+ }
152
152
  //# 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,sDAA4C;AAC5C,oDAAoD;AAEpD,oEAGoC;AACpC,4EAAmH;AACnH,wEAA4D;AAiD5D;;;GAGG;AACH,MAAa,cAAc;IAKzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,CAAC;IAClD,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAA2B,EAAE,WAAmB;QAC/F,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAA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C;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":["/*---------------------------------------------------------------------------------------------\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 // eslint-disable-next-line deprecation/deprecation\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 // eslint-disable-next-line deprecation/deprecation\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 * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\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 * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\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
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAG/F;;GAEG;AACH,sDAA4C;AAC5C,oDAAoD;AAEpD,oEAGoC;AACpC,4EAAmH;AACnH,wEAA4D;AAiD5D;;;GAGG;AACH,MAAa,cAAc;IAKzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,CAAC;IAClD,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAA2B,EAAE,WAAmB;QAC/F,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,6CAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAClJ,YAAY,CAAC,IAAI,GAAG,IAAI,4BAAM,CAAC,YAAY,CAAC,CAAC;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AC,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 // eslint-disable-next-line deprecation/deprecation\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 // eslint-disable-next-line deprecation/deprecation\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 * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\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 * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\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) });\n }\n}\n"]}