@itwin/presentation-testing 5.4.8 → 5.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log - @itwin/presentation-testing
2
2
 
3
+ ## 5.4.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1088](https://github.com/iTwin/presentation/pull/1088): Fix restart tokens not being unique when they need to, causing queries to be cancelled.
8
+ - Updated dependencies:
9
+ - @itwin/presentation-components@5.12.12
10
+
3
11
  ## 5.4.8
4
12
 
5
13
  ### Patch Changes
@@ -130,7 +130,7 @@ class ContentBuilder {
130
130
  INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
131
131
  WHERE c.Modifier <> 1 AND c.Type = 0
132
132
  ORDER BY s.Name, c.Name
133
- `, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names` });
133
+ `, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names/${core_bentley_1.Guid.createValue()}` });
134
134
  return reader.toArray();
135
135
  }
136
136
  async createContentForClasses(rulesetOrId, limitInstances, displayType) {
@@ -143,7 +143,7 @@ class ContentBuilder {
143
143
  `, undefined, {
144
144
  rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames,
145
145
  limit: { count: limitInstances ? 1 : 4000 },
146
- restartToken: `${this.#componentName}/${this.#componentId}/instance-id`,
146
+ restartToken: `${this.#componentName}/${this.#componentId}/instance-id/${core_bentley_1.Guid.createValue()}`,
147
147
  });
148
148
  const instanceIds = await reader.toArray();
149
149
  if (!instanceIds.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;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,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/** @packageDocumentation\n * @module Content\n */\n\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content,\n DefaultContentDisplayTypes,\n InstanceId,\n InstanceKey,\n KeySet,\n PageOptions,\n ProcessPrimitiveValueProps,\n Ruleset,\n traverseContent,\n Value,\n ValuesMap,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { safeDispose } from \"./Helpers.js\";\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 #componentName: string;\n #componentId: GuidString;\n\n /**\n * Constructor\n * @param iModel\n * @param dataProvider\n */\n constructor(props: ContentBuilderProps) {\n this.#componentId = Guid.createValue();\n this.#componentName = \"ContentBuilder\";\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\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]($presentation-common) 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 const ruleset = await Presentation.presentation.rulesets().add(rulesetOrId);\n using _ = { [Symbol.dispose]: () => safeDispose(ruleset) };\n return await this.doCreateContent(ruleset.id, instanceKeys, displayType);\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string; className: string }>> {\n const reader = this._iModel.createQueryReader(\n `\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 `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names` },\n );\n return reader.toArray();\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 const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n {\n rowFormat: QueryRowFormat.UseJsPropertyNames,\n limit: { count: limitInstances ? 1 : 4000 },\n restartToken: `${this.#componentName}/${this.#componentId}/instance-id`,\n },\n );\n const instanceIds: InstanceId[] = await reader.toArray();\n\n if (!instanceIds.length) {\n continue;\n }\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]($presentation-common) 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]($presentation-common) 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((record) => {\n this._records.push(record);\n });\n this._decimalPrecision = decimalPrecision;\n }\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n private processRawValue(value: Value): Value {\n if (this._decimalPrecision === undefined) {\n return value;\n }\n\n if (typeof value === \"number\") {\n return +Number(value).toFixed(this._decimalPrecision);\n }\n\n if (Value.isArray(value)) {\n return value.map((item) => this.processRawValue(item));\n }\n\n if (Value.isMap(value)) {\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"]}
1
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,sDAAuD;AACvD,oDAAoD;AAEpD,oEAYoC;AACpC,4EAA6F;AAC7F,wEAA4D;AAC5D,6CAA2C;AAiD3C;;;GAGG;AACH,MAAa,cAAc;IACR,OAAO,CAAmB;IACnC,aAAa,C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,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/** @packageDocumentation\n * @module Content\n */\n\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content,\n DefaultContentDisplayTypes,\n InstanceId,\n InstanceKey,\n KeySet,\n PageOptions,\n ProcessPrimitiveValueProps,\n Ruleset,\n traverseContent,\n Value,\n ValuesMap,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { safeDispose } from \"./Helpers.js\";\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 #componentName: string;\n #componentId: GuidString;\n\n /**\n * Constructor\n * @param iModel\n * @param dataProvider\n */\n constructor(props: ContentBuilderProps) {\n this.#componentId = Guid.createValue();\n this.#componentName = \"ContentBuilder\";\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\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]($presentation-common) 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 const ruleset = await Presentation.presentation.rulesets().add(rulesetOrId);\n using _ = { [Symbol.dispose]: () => safeDispose(ruleset) };\n return await this.doCreateContent(ruleset.id, instanceKeys, displayType);\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string; className: string }>> {\n const reader = this._iModel.createQueryReader(\n `\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 `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names/${Guid.createValue()}` },\n );\n return reader.toArray();\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 const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n {\n rowFormat: QueryRowFormat.UseJsPropertyNames,\n limit: { count: limitInstances ? 1 : 4000 },\n restartToken: `${this.#componentName}/${this.#componentId}/instance-id/${Guid.createValue()}`,\n },\n );\n const instanceIds: InstanceId[] = await reader.toArray();\n\n if (!instanceIds.length) {\n continue;\n }\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]($presentation-common) 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]($presentation-common) 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((record) => {\n this._records.push(record);\n });\n this._decimalPrecision = decimalPrecision;\n }\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n private processRawValue(value: Value): Value {\n if (this._decimalPrecision === undefined) {\n return value;\n }\n\n if (typeof value === \"number\") {\n return +Number(value).toFixed(this._decimalPrecision);\n }\n\n if (Value.isArray(value)) {\n return value.map((item) => this.processRawValue(item));\n }\n\n if (Value.isMap(value)) {\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"]}
@@ -127,7 +127,7 @@ export class ContentBuilder {
127
127
  INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
128
128
  WHERE c.Modifier <> 1 AND c.Type = 0
129
129
  ORDER BY s.Name, c.Name
130
- `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names` });
130
+ `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names/${Guid.createValue()}` });
131
131
  return reader.toArray();
132
132
  }
133
133
  async createContentForClasses(rulesetOrId, limitInstances, displayType) {
@@ -140,7 +140,7 @@ export class ContentBuilder {
140
140
  `, undefined, {
141
141
  rowFormat: QueryRowFormat.UseJsPropertyNames,
142
142
  limit: { count: limitInstances ? 1 : 4000 },
143
- restartToken: `${this.#componentName}/${this.#componentId}/instance-id`,
143
+ restartToken: `${this.#componentName}/${this.#componentId}/instance-id/${Guid.createValue()}`,
144
144
  });
145
145
  const instanceIds = await reader.toArray();
146
146
  if (!instanceIds.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,0BAA0B,EAG1B,MAAM,EAIN,eAAe,EACf,KAAK,GAEN,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAiD3C;;;GAGG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAAmB;IACnC,aAAa,CAA0C;IACvD,iBAAiB,CAAU;IACnC,cAAc,CAAS;IACvB,YAAY,CAAa;IAEzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,gBAAgB,CAAC;QACvC,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,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;QACxD,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,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;QACb,CAAC;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/** @packageDocumentation\n * @module Content\n */\n\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content,\n DefaultContentDisplayTypes,\n InstanceId,\n InstanceKey,\n KeySet,\n PageOptions,\n ProcessPrimitiveValueProps,\n Ruleset,\n traverseContent,\n Value,\n ValuesMap,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { safeDispose } from \"./Helpers.js\";\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 #componentName: string;\n #componentId: GuidString;\n\n /**\n * Constructor\n * @param iModel\n * @param dataProvider\n */\n constructor(props: ContentBuilderProps) {\n this.#componentId = Guid.createValue();\n this.#componentName = \"ContentBuilder\";\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\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]($presentation-common) 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 const ruleset = await Presentation.presentation.rulesets().add(rulesetOrId);\n using _ = { [Symbol.dispose]: () => safeDispose(ruleset) };\n return await this.doCreateContent(ruleset.id, instanceKeys, displayType);\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string; className: string }>> {\n const reader = this._iModel.createQueryReader(\n `\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 `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names` },\n );\n return reader.toArray();\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 const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n {\n rowFormat: QueryRowFormat.UseJsPropertyNames,\n limit: { count: limitInstances ? 1 : 4000 },\n restartToken: `${this.#componentName}/${this.#componentId}/instance-id`,\n },\n );\n const instanceIds: InstanceId[] = await reader.toArray();\n\n if (!instanceIds.length) {\n continue;\n }\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]($presentation-common) 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]($presentation-common) 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((record) => {\n this._records.push(record);\n });\n this._decimalPrecision = decimalPrecision;\n }\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n private processRawValue(value: Value): Value {\n if (this._decimalPrecision === undefined) {\n return value;\n }\n\n if (typeof value === \"number\") {\n return +Number(value).toFixed(this._decimalPrecision);\n }\n\n if (Value.isArray(value)) {\n return value.map((item) => this.processRawValue(item));\n }\n\n if (Value.isMap(value)) {\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"]}
1
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,0BAA0B,EAG1B,MAAM,EAIN,eAAe,EACf,KAAK,GAEN,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAiD3C;;;GAGG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAAmB;IACnC,aAAa,CAA0C;IACvD,iBAAiB,CAAU;IACnC,cAAc,CAAS;IACvB,YAAY,CAAa;IAEzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,gBAAgB,CAAC;QACvC,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,CA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OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,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;QACb,CAAC;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/** @packageDocumentation\n * @module Content\n */\n\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content,\n DefaultContentDisplayTypes,\n InstanceId,\n InstanceKey,\n KeySet,\n PageOptions,\n ProcessPrimitiveValueProps,\n Ruleset,\n traverseContent,\n Value,\n ValuesMap,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { safeDispose } from \"./Helpers.js\";\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 #componentName: string;\n #componentId: GuidString;\n\n /**\n * Constructor\n * @param iModel\n * @param dataProvider\n */\n constructor(props: ContentBuilderProps) {\n this.#componentId = Guid.createValue();\n this.#componentName = \"ContentBuilder\";\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\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]($presentation-common) 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 const ruleset = await Presentation.presentation.rulesets().add(rulesetOrId);\n using _ = { [Symbol.dispose]: () => safeDispose(ruleset) };\n return await this.doCreateContent(ruleset.id, instanceKeys, displayType);\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string; className: string }>> {\n const reader = this._iModel.createQueryReader(\n `\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 `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, restartToken: `${this.#componentName}/${this.#componentId}/ec-class-names/${Guid.createValue()}` },\n );\n return reader.toArray();\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 const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n {\n rowFormat: QueryRowFormat.UseJsPropertyNames,\n limit: { count: limitInstances ? 1 : 4000 },\n restartToken: `${this.#componentName}/${this.#componentId}/instance-id/${Guid.createValue()}`,\n },\n );\n const instanceIds: InstanceId[] = await reader.toArray();\n\n if (!instanceIds.length) {\n continue;\n }\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]($presentation-common) 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]($presentation-common) 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((record) => {\n this._records.push(record);\n });\n this._decimalPrecision = decimalPrecision;\n }\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n private processRawValue(value: Value): Value {\n if (this._decimalPrecision === undefined) {\n return value;\n }\n\n if (typeof value === \"number\") {\n return +Number(value).toFixed(this._decimalPrecision);\n }\n\n if (Value.isArray(value)) {\n return value.map((item) => this.processRawValue(item));\n }\n\n if (Value.isMap(value)) {\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-testing",
3
- "version": "5.4.8",
3
+ "version": "5.4.9",
4
4
  "description": "Testing utilities for iTwin.js Presentation library",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "rimraf": "^6.0.1",
34
34
  "sanitize-filename": "^1.6.3",
35
- "@itwin/presentation-components": "^5.12.11"
35
+ "@itwin/presentation-components": "^5.12.12"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@itwin/appui-abstract": "^4.1.0 || ^5.0.0",