@itwin/presentation-testing 5.3.1 → 5.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log - @itwin/presentation-testing
2
2
 
3
+ ## 5.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#834](https://github.com/iTwin/presentation/pull/834): Added `TestIModelConnection` that allows opening iModels from local files without the use of deprecated iTwin.js Core APIs.
8
+ - [#834](https://github.com/iTwin/presentation/pull/834): Updated peer dependencies to support iTwin.js Core v5 packages.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies:
13
+ - @itwin/presentation-components@5.11.0
14
+
3
15
  ## 5.3.1
4
16
 
5
17
  ### Patch Changes
@@ -1 +1 @@
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,EAGP,WAAW,EACX,MAAM,EACN,WAAW,EAGX,OAAO,EAIR,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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AiB,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;IAc7B;;;;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,WAAW,GAAE,MAAgD;YAQtI,eAAe;YAcf,uBAAuB;IAgCrC;;;;;;;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"}
@@ -6,9 +6,60 @@
6
6
  /** @packageDocumentation
7
7
  * @module Content
8
8
  */
9
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
10
+ if (value !== null && value !== void 0) {
11
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
12
+ var dispose, inner;
13
+ if (async) {
14
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
15
+ dispose = value[Symbol.asyncDispose];
16
+ }
17
+ if (dispose === void 0) {
18
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
19
+ dispose = value[Symbol.dispose];
20
+ if (async) inner = dispose;
21
+ }
22
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
23
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
24
+ env.stack.push({ value: value, dispose: dispose, async: async });
25
+ }
26
+ else if (async) {
27
+ env.stack.push({ async: true });
28
+ }
29
+ return value;
30
+ };
31
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
32
+ return function (env) {
33
+ function fail(e) {
34
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
35
+ env.hasError = true;
36
+ }
37
+ var r, s = 0;
38
+ function next() {
39
+ while (r = env.stack.pop()) {
40
+ try {
41
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
42
+ if (r.dispose) {
43
+ var result = r.dispose.call(r.value);
44
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
45
+ }
46
+ else s |= 1;
47
+ }
48
+ catch (e) {
49
+ fail(e);
50
+ }
51
+ }
52
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
53
+ if (env.hasError) throw env.error;
54
+ }
55
+ return next();
56
+ };
57
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
58
+ var e = new Error(message);
59
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
60
+ });
9
61
  Object.defineProperty(exports, "__esModule", { value: true });
10
62
  exports.ContentBuilder = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
63
  const core_common_1 = require("@itwin/core-common");
13
64
  const presentation_common_1 = require("@itwin/presentation-common");
14
65
  const presentation_components_1 = require("@itwin/presentation-components");
@@ -50,12 +101,21 @@ class ContentBuilder {
50
101
  * "PropertyPane", "Grid", "List" etc.
51
102
  */
52
103
  async createContent(rulesetOrId, instanceKeys, displayType = presentation_common_1.DefaultContentDisplayTypes.PropertyPane) {
53
- if (typeof rulesetOrId === "string") {
54
- return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
104
+ const env_1 = { stack: [], error: void 0, hasError: false };
105
+ try {
106
+ if (typeof rulesetOrId === "string") {
107
+ return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
108
+ }
109
+ const ruleset = __addDisposableResource(env_1, await presentation_frontend_1.Presentation.presentation.rulesets().add(rulesetOrId), false);
110
+ return await this.doCreateContent(ruleset.id, instanceKeys, displayType);
111
+ }
112
+ catch (e_1) {
113
+ env_1.error = e_1;
114
+ env_1.hasError = true;
115
+ }
116
+ finally {
117
+ __disposeResources(env_1);
55
118
  }
56
- return (0, core_bentley_1.using)(await presentation_frontend_1.Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
57
- return this.doCreateContent(ruleset.id, instanceKeys, displayType);
58
- });
59
119
  }
60
120
  async getECClassNames() {
61
121
  const reader = this._iModel.createQueryReader(`
@@ -1 +1 @@
1
- {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAGH,sDAA4C;AAC5C,oDAAoD;AAEpD,oEAaoC;AACpC,4EAA6F;AAC7F,wEAA4D;AAiD5D;;;GAGG;AACH,MAAa,cAAc;IACR,OAAO,CAAmB;IACnC,aAAa,CAA0C;IACvD,iBAAiB,CAAU;IAEnC;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACx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CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;YAC5B,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 { using } 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 RegisteredRuleset,\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\";\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\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\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 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 },\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 // try {\n const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } },\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 (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"]}
1
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.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vB,CAAC;IAEO,eAAe,CAAC,KAAY;QAClC,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,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,YAAY,MAAM,EAAE,CAAC;YAC5B,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 { 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\";\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\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 using ruleset = await Presentation.presentation.rulesets().add(rulesetOrId);\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 },\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 // try {\n const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } },\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 (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"]}
@@ -10,7 +10,7 @@ export { HierarchyCacheMode, PresentationBackendProps };
10
10
  /** @public */
11
11
  export interface PresentationTestingInitProps {
12
12
  /**
13
- * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.
13
+ * RPC interfaces to enable. Defaults to `[IModelReadRpcInterface, PresentationRpcInterface]`.
14
14
  *
15
15
  * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.
16
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAqE,sBAAsB,EAA8B,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAGlB,wBAAwB,IAAI,wBAAwB,EACrD,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA2BpI,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;AAExD,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,IAAI,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAChC,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,C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O,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBA8CpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
@@ -83,7 +83,7 @@ const initialize = async (props) => {
83
83
  core_bentley_1.Logger.setLevel("SQLite", core_bentley_1.LogLevel.Error);
84
84
  core_bentley_1.Logger.setLevel(presentation_backend_1.PresentationBackendNativeLoggerCategory.ECObjects, core_bentley_1.LogLevel.Warning);
85
85
  // set up rpc interfaces
86
- initializeRpcInterfaces(props.rpcs ?? [core_common_1.SnapshotIModelRpcInterface, core_common_1.IModelReadRpcInterface, presentation_common_1.PresentationRpcInterface]);
86
+ initializeRpcInterfaces(props.rpcs ?? [core_common_1.IModelReadRpcInterface, presentation_common_1.PresentationRpcInterface]);
87
87
  // init backend
88
88
  // make sure backend gets assigned an id which puts its resources into a unique directory
89
89
  props.backendProps = props.backendProps ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA6D;AAC7D,oDAA2J;AAC3J,wDAAgF;AAChF,sEAKqC;AA6B5B,mGAjCP,yCAAkB,OAiCO;AA5B3B,oEAAsE;AACtE,wEAAoI;AACpI,yDAAwE;AAExE,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAClC,UAAU,GAAQ,GAAG,EA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BAA6C,CAAC;IAClD,MAAM,sBAAsB,GAAG,mCAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC;IACnF,IAAI,sBAAsB,EAAE,IAAI,KAAK,yCAAkB,CAAC,IAAI,EAAE,CAAC;QAC7D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;IAChE,CAAC;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,yCAAkB,CAAC,MAAM,EAAE,CAAC;QACtE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IACtE,CAAC;IAED,oBAAoB;IACpB,mCAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,yBAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;IAED,qBAAqB;IACrB,oCAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC;AA1BW,QAAA,SAAS,aA0BpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid, Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationBackendNativeLoggerCategory,\n PresentationManagerProps as PresentationBackendProps,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { getTestOutputDir, setTestOutputDir } from \"./FilenameUtils.js\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n // eslint-disable-next-line @itwin/no-internal\n RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n /* c8 ignore start */\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n /* c8 ignore end */\n}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /**\n * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.\n *\n * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.\n */\n rpcs?: RpcInterfaceDefinition[];\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n Logger.initializeToConsole();\n Logger.setLevelDefault(LogLevel.Warning);\n Logger.setLevel(\"i18n\", LogLevel.Error);\n Logger.setLevel(\"SQLite\", LogLevel.Error);\n Logger.setLevel(PresentationBackendNativeLoggerCategory.ECObjects, LogLevel.Warning);\n\n // set up rpc interfaces\n initializeRpcInterfaces(props.rpcs ?? [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({\n cacheDir: join(getTestOutputDir(), \".cache\", `${process.pid}`),\n ...props.backendHostProps,\n });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n setTestOutputDir(props.testOutputDir);\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
1
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA6D;AAC7D,oDAA+H;AAC/H,wDAAgF;AAChF,sEAKqC;AA6B5B,mGAjCP,yCAAkB,OAiCO;AA5B3B,oEAAsE;AACtE,wEAAoI;AACpI,yDAAwE;AAExE,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAClC,UAAU,GAAQ,GAAG,EAAE,CAAC,UAAU,CAAC;KACpD,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACpC,8CAA8C;QAC9C,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,0BAA0B,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAChD,qBAAqB;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,kFAAkF;QAClF,yDAAyD;IAC3D,CAAC;IACD,mBAAmB;AACrB,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,CAAC;AA0B1B;;;;;;;GAOG;AACI,MAAM,UAAU,GAAG,KAAK,EAAE,KAAoC,EAAE,EAAE;IACvE,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,EAAE,C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,CAAC;AA1BW,QAAA,SAAS,aA0BpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid, Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationBackendNativeLoggerCategory,\n PresentationManagerProps as PresentationBackendProps,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { getTestOutputDir, setTestOutputDir } from \"./FilenameUtils.js\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n // eslint-disable-next-line @itwin/no-internal\n RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n /* c8 ignore start */\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n /* c8 ignore end */\n}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /**\n * RPC interfaces to enable. Defaults to `[IModelReadRpcInterface, PresentationRpcInterface]`.\n *\n * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.\n */\n rpcs?: RpcInterfaceDefinition[];\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n Logger.initializeToConsole();\n Logger.setLevelDefault(LogLevel.Warning);\n Logger.setLevel(\"i18n\", LogLevel.Error);\n Logger.setLevel(\"SQLite\", LogLevel.Error);\n Logger.setLevel(PresentationBackendNativeLoggerCategory.ECObjects, LogLevel.Warning);\n\n // set up rpc interfaces\n\n initializeRpcInterfaces(props.rpcs ?? [IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({\n cacheDir: join(getTestOutputDir(), \".cache\", `${process.pid}`),\n ...props.backendHostProps,\n });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n setTestOutputDir(props.testOutputDir);\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  /** @packageDocumentation
2
2
  * @module IModel
3
3
  */
4
+ import { IModelDb } from "@itwin/core-backend";
4
5
  import { Id64String } from "@itwin/core-bentley";
5
6
  import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from "@itwin/core-common";
6
7
  import { IModelConnection } from "@itwin/core-frontend";
@@ -60,4 +61,15 @@ export declare function buildTestIModel(mochaContext: Mocha.Context, cb: (builde
60
61
  * @beta
61
62
  */
62
63
  export declare function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;
64
+ /**
65
+ * Implementation of `IModelConnection` that allows opening local files in tests.
66
+ * @beta
67
+ */
68
+ export declare class TestIModelConnection extends IModelConnection {
69
+ private readonly _db;
70
+ constructor(_db: IModelDb);
71
+ get isClosed(): boolean;
72
+ close(): Promise<void>;
73
+ static openFile(filePath: string): IModelConnection;
74
+ }
63
75
  //# sourceMappingURL=IModelUtilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxI,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAI5E;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,+CAA+C;IAC/C,WAAW,CAAC,MAAM,SAAS,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IAClE,kDAAkD;IAClD,aAAa,CAAC,MAAM,SAAS,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACtE,0DAA0D;IAC1D,YAAY,CAAC,MAAM,SAAS,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IAC3E;;;OAGG;IACH,kBAAkB,CAAC,MAAM,SAAS,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IAChF;;;OAGG;IACH,UAAU,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7F;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACzH;;;;;GAKG;AAEH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CA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
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TestIModelConnection = void 0;
10
11
  exports.buildTestIModel = buildTestIModel;
11
12
  const core_backend_1 = require("@itwin/core-backend");
12
13
  const core_frontend_1 = require("@itwin/core-frontend");
@@ -24,6 +25,33 @@ async function buildTestIModel(nameParam, cb) {
24
25
  db.saveChanges("Created test IModel");
25
26
  db.close();
26
27
  }
27
- return core_frontend_1.SnapshotConnection.openFile(outputFile);
28
+ return TestIModelConnection.openFile(outputFile);
28
29
  }
30
+ /**
31
+ * Implementation of `IModelConnection` that allows opening local files in tests.
32
+ * @beta
33
+ */
34
+ /* c8 ignore start */
35
+ class TestIModelConnection extends core_frontend_1.IModelConnection {
36
+ _db;
37
+ // This was added based on this: https://github.com/iTwin/itwinjs-core/pull/7171/files#diff-9d26b04e7ae074b911fb87be3425360d7bd55a7c9f947f5aed1ba36d359f01eb
38
+ constructor(_db) {
39
+ // eslint-disable-next-line @itwin/no-internal
40
+ super(_db.getConnectionProps());
41
+ this._db = _db;
42
+ core_frontend_1.IModelConnection.onOpen.raiseEvent(this);
43
+ }
44
+ get isClosed() {
45
+ // eslint-disable-next-line @itwin/no-internal
46
+ return !this._db.isOpen;
47
+ }
48
+ async close() {
49
+ this._db.close();
50
+ }
51
+ static openFile(filePath) {
52
+ return new TestIModelConnection(core_backend_1.SnapshotDb.openFile(filePath));
53
+ }
54
+ }
55
+ exports.TestIModelConnection = TestIModelConnection;
56
+ /* c8 ignore end */
29
57
  //# sourceMappingURL=IModelUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;AAqEH,0CAYC;AA/ED,sDAAiD;AAGjD,wDAA4E;AAC5E,yDAAuF;AACvF,iEAA+D;AA8DxD,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,2CAAwB,EAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,IAAA,0CAAuB,EAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,yBAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,4CAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,kCAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACjD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module IModel\n */\n\nimport { SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./FilenameUtils.js\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl.js\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n /**\n * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<void>): Promise<IModelConnection> {\n const name = typeof nameParam === \"string\" ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(`${name}.bim`);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n"]}
1
+ {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAqEH,0CAYC;AA/ED,sDAA2D;AAG3D,wDAAwD;AACxD,yDAAuF;AACvF,iEAA+D;AA8DxD,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,2CAAwB,EAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,IAAA,0CAAuB,EAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,yBAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,4CAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,qBAAqB;AACrB,MAAa,oBAAqB,SAAQ,gCAAgB;IAE3B;IAD7B,4JAA4J;IAC5J,YAA6B,GAAa;QACxC,8CAA8C;QAC9C,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,CAAC;QAFL,QAAG,GAAH,GAAG,CAAU;QAGxC,gCAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,IAAoB,QAAQ;QAC1B,8CAA8C;QAC9C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,KAAK;QACzB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,QAAgB;QACrC,OAAO,IAAI,oBAAoB,CAAC,yBAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjE,CAAC;CACF;AApBD,oDAoBC;AACD,mBAAmB","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 IModel\n */\n\nimport { IModelDb, SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./FilenameUtils.js\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl.js\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n /**\n * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<void>): Promise<IModelConnection> {\n const name = typeof nameParam === \"string\" ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(`${name}.bim`);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return TestIModelConnection.openFile(outputFile);\n}\n\n/**\n * Implementation of `IModelConnection` that allows opening local files in tests.\n * @beta\n */\n/* c8 ignore start */\nexport class TestIModelConnection extends IModelConnection {\n // This was added based on this: https://github.com/iTwin/itwinjs-core/pull/7171/files#diff-9d26b04e7ae074b911fb87be3425360d7bd55a7c9f947f5aed1ba36d359f01eb\n constructor(private readonly _db: IModelDb) {\n // eslint-disable-next-line @itwin/no-internal\n super(_db.getConnectionProps());\n IModelConnection.onOpen.raiseEvent(this);\n }\n\n public override get isClosed(): boolean {\n // eslint-disable-next-line @itwin/no-internal\n return !this._db.isOpen;\n }\n\n public override async close(): Promise<void> {\n this._db.close();\n }\n\n public static openFile(filePath: string): IModelConnection {\n return new TestIModelConnection(SnapshotDb.openFile(filePath));\n }\n}\n/* c8 ignore end */\n"]}
@@ -1 +1 @@
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,EAGP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;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,WAAW,GAAE,MAAgD;YAQtI,eAAe;YAcf,uBAAuB;IAgCrC;;;;;;;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"}
@@ -5,7 +5,58 @@
5
5
  /** @packageDocumentation
6
6
  * @module Content
7
7
  */
8
- import { using } from "@itwin/core-bentley";
8
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
9
+ if (value !== null && value !== void 0) {
10
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
11
+ var dispose, inner;
12
+ if (async) {
13
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
14
+ dispose = value[Symbol.asyncDispose];
15
+ }
16
+ if (dispose === void 0) {
17
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
18
+ dispose = value[Symbol.dispose];
19
+ if (async) inner = dispose;
20
+ }
21
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
22
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
23
+ env.stack.push({ value: value, dispose: dispose, async: async });
24
+ }
25
+ else if (async) {
26
+ env.stack.push({ async: true });
27
+ }
28
+ return value;
29
+ };
30
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
31
+ return function (env) {
32
+ function fail(e) {
33
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
34
+ env.hasError = true;
35
+ }
36
+ var r, s = 0;
37
+ function next() {
38
+ while (r = env.stack.pop()) {
39
+ try {
40
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
41
+ if (r.dispose) {
42
+ var result = r.dispose.call(r.value);
43
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
44
+ }
45
+ else s |= 1;
46
+ }
47
+ catch (e) {
48
+ fail(e);
49
+ }
50
+ }
51
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
52
+ if (env.hasError) throw env.error;
53
+ }
54
+ return next();
55
+ };
56
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
57
+ var e = new Error(message);
58
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
59
+ });
9
60
  import { QueryRowFormat } from "@itwin/core-common";
10
61
  import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
11
62
  import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
@@ -47,12 +98,21 @@ export class ContentBuilder {
47
98
  * "PropertyPane", "Grid", "List" etc.
48
99
  */
49
100
  async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
50
- if (typeof rulesetOrId === "string") {
51
- return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
101
+ const env_1 = { stack: [], error: void 0, hasError: false };
102
+ try {
103
+ if (typeof rulesetOrId === "string") {
104
+ return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
105
+ }
106
+ const ruleset = __addDisposableResource(env_1, await Presentation.presentation.rulesets().add(rulesetOrId), false);
107
+ return await this.doCreateContent(ruleset.id, instanceKeys, displayType);
108
+ }
109
+ catch (e_1) {
110
+ env_1.error = e_1;
111
+ env_1.hasError = true;
112
+ }
113
+ finally {
114
+ __disposeResources(env_1);
52
115
  }
53
- return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
54
- return this.doCreateContent(ruleset.id, instanceKeys, displayType);
55
- });
56
116
  }
57
117
  async getECClassNames() {
58
118
  const reader = this._iModel.createQueryReader(`
@@ -1 +1 @@
1
- {"version":3,"file":"ContentB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AAC;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 { using } 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 RegisteredRuleset,\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\";\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\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\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 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 },\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 // try {\n const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } },\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 (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"]}
1
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,0BAA0B,EAG1B,MAAM,EAIN,eAAe,GAGhB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiD5D;;;GAGG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAAmB;IACnC,aAAa,CAA0C;IACvD,iBAAiB,CAAU;IAEnC;;;;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,iB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,CAAC;QAED,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;YAC5B,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 { 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\";\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\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 using ruleset = await Presentation.presentation.rulesets().add(rulesetOrId);\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 },\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 // try {\n const reader = this._iModel.createQueryReader(\n `\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId\n `,\n undefined,\n { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } },\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 (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"]}
@@ -10,7 +10,7 @@ export { HierarchyCacheMode, PresentationBackendProps };
10
10
  /** @public */
11
11
  export interface PresentationTestingInitProps {
12
12
  /**
13
- * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.
13
+ * RPC interfaces to enable. Defaults to `[IModelReadRpcInterface, PresentationRpcInterface]`.
14
14
  *
15
15
  * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.
16
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAqE,sBAAsB,EAA8B,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAGlB,wBAAwB,IAAI,wBAAwB,EACrD,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA2BpI,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;AAExD,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,IAAI,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAChC,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBA6CpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAqE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC/H,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAGlB,wBAAwB,IAAI,wBAAwB,EACrD,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AA2BpI,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;AAExD,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,IAAI,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAChC,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,WAAkB,4BAA4B,kBA8CpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDA0BrB,CAAC"}
@@ -9,7 +9,7 @@ import { join } from "path";
9
9
  import * as rimraf from "rimraf";
10
10
  import { IModelHost } from "@itwin/core-backend";
11
11
  import { Guid, Logger, LogLevel } from "@itwin/core-bentley";
12
- import { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, SnapshotIModelRpcInterface } from "@itwin/core-common";
12
+ import { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration } from "@itwin/core-common";
13
13
  import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
14
14
  import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationBackendNativeLoggerCategory, } from "@itwin/presentation-backend";
15
15
  import { PresentationRpcInterface } from "@itwin/presentation-common";
@@ -57,7 +57,7 @@ export const initialize = async (props) => {
57
57
  Logger.setLevel("SQLite", LogLevel.Error);
58
58
  Logger.setLevel(PresentationBackendNativeLoggerCategory.ECObjects, LogLevel.Warning);
59
59
  // set up rpc interfaces
60
- initializeRpcInterfaces(props.rpcs ?? [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
60
+ initializeRpcInterfaces(props.rpcs ?? [IModelReadRpcInterface, PresentationRpcInterface]);
61
61
  // init backend
62
62
  // make sure backend gets assigned an id which puts its resources into a unique directory
63
63
  props.backendProps = props.backendProps ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAA0B,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC3J,OAAO,EAAE,SAAS,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,YAAY,IAAI,mBAAmB,EAC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B,EAAE,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC3F,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAEtC,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,WAAW,GAAG,SAAS,EAAE,EAAE;IACzD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IAED,8CAA8C;IAC9C,IAAI,yBAA6C,CAAC;IAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC;IACnF,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAC7D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;IAChE,CAAC;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;QACtE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IACtE,CAAC;IAED,oBAAoB;IACpB,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;IAED,qBAAqB;IACrB,oBAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid, Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationBackendNativeLoggerCategory,\n PresentationManagerProps as PresentationBackendProps,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { getTestOutputDir, setTestOutputDir } from \"./FilenameUtils.js\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n // eslint-disable-next-line @itwin/no-internal\n RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n /* c8 ignore start */\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n /* c8 ignore end */\n}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /**\n * RPC interfaces to enable. Defaults to `[SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]`.\n *\n * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.\n */\n rpcs?: RpcInterfaceDefinition[];\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n Logger.initializeToConsole();\n Logger.setLevelDefault(LogLevel.Warning);\n Logger.setLevel(\"i18n\", LogLevel.Error);\n Logger.setLevel(\"SQLite\", LogLevel.Error);\n Logger.setLevel(PresentationBackendNativeLoggerCategory.ECObjects, LogLevel.Warning);\n\n // set up rpc interfaces\n initializeRpcInterfaces(props.rpcs ?? [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({\n cacheDir: join(getTestOutputDir(), \".cache\", `${process.pid}`),\n ...props.backendHostProps,\n });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n setTestOutputDir(props.testOutputDir);\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
1
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAA0B,MAAM,oBAAoB,CAAC;AAC/H,OAAO,EAAE,SAAS,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,YAAY,IAAI,mBAAmB,EACnC,uCAAuC,GAExC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAkD,MAAM,8BAA8B,CAAC;AACpI,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAExE,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,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ACnB,OAAO;IACT,CAAC;IAED,8CAA8C;IAC9C,IAAI,yBAA6C,CAAC;IAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC;IACnF,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAC7D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;IAChE,CAAC;SAAM,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;QACtE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IACtE,CAAC;IAED,oBAAoB;IACpB,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;IAED,qBAAqB;IACrB,oBAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Helpers\n */\n\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid, Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition } from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode,\n Presentation as PresentationBackend,\n PresentationBackendNativeLoggerCategory,\n PresentationManagerProps as PresentationBackendProps,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\nimport { getTestOutputDir, setTestOutputDir } from \"./FilenameUtils.js\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces) {\n // eslint-disable-next-line @itwin/no-internal\n RpcConfiguration.assign(definition, /* istanbul ignore next */ () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n /* c8 ignore start */\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n /* c8 ignore end */\n}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /**\n * RPC interfaces to enable. Defaults to `[IModelReadRpcInterface, PresentationRpcInterface]`.\n *\n * Note: Implementations for these interfaces are **not** automatically registered on the backend - that has to be done manually.\n */\n rpcs?: RpcInterfaceDefinition[];\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized) {\n return;\n }\n\n if (!props) {\n props = {};\n }\n\n Logger.initializeToConsole();\n Logger.setLevelDefault(LogLevel.Warning);\n Logger.setLevel(\"i18n\", LogLevel.Error);\n Logger.setLevel(\"SQLite\", LogLevel.Error);\n Logger.setLevel(PresentationBackendNativeLoggerCategory.ECObjects, LogLevel.Warning);\n\n // set up rpc interfaces\n\n initializeRpcInterfaces(props.rpcs ?? [IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n // eslint-disable-next-line @itwin/no-internal\n if (!props.backendProps.id) {\n props.backendProps.id = `test-${Guid.createValue()}`; // eslint-disable-line @itwin/no-internal\n }\n await IModelHost.startup({\n cacheDir: join(getTestOutputDir(), \".cache\", `${process.pid}`),\n ...props.backendHostProps,\n });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp) {\n props.frontendApp = NoRenderApp;\n }\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n setTestOutputDir(props.testOutputDir);\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized) {\n return;\n }\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n } else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid) {\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n }\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory) {\n rimraf.sync(hierarchiesCacheDirectory);\n }\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  /** @packageDocumentation
2
2
  * @module IModel
3
3
  */
4
+ import { IModelDb } from "@itwin/core-backend";
4
5
  import { Id64String } from "@itwin/core-bentley";
5
6
  import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from "@itwin/core-common";
6
7
  import { IModelConnection } from "@itwin/core-frontend";
@@ -60,4 +61,15 @@ export declare function buildTestIModel(mochaContext: Mocha.Context, cb: (builde
60
61
  * @beta
61
62
  */
62
63
  export declare function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;
64
+ /**
65
+ * Implementation of `IModelConnection` that allows opening local files in tests.
66
+ * @beta
67
+ */
68
+ export declare class TestIModelConnection extends IModelConnection {
69
+ private readonly _db;
70
+ constructor(_db: IModelDb);
71
+ get isClosed(): boolean;
72
+ close(): Promise<void>;
73
+ static openFile(filePath: string): IModelConnection;
74
+ }
63
75
  //# sourceMappingURL=IModelUtilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxI,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAI5E;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,+CAA+C;IAC/C,WAAW,CAAC,MAAM,SAAS,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IAClE,kDAAkD;I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I,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAClI;;;;;;GAMG;AAEH,wBAAsB,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACxI;;;;;GAKG;AAEH,wBAAsB,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAejJ;;;GAGG;AAEH,qBAAa,oBAAqB,SAAQ,gBAAgB;IAE5C,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,QAAQ;IAM1C,IAAoB,QAAQ,IAAI,OAAO,CAGtC;IAEqB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;WAI9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;CAG3D"}
@@ -6,7 +6,7 @@
6
6
  * @module IModel
7
7
  */
8
8
  import { SnapshotDb } from "@itwin/core-backend";
9
- import { SnapshotConnection } from "@itwin/core-frontend";
9
+ import { IModelConnection } from "@itwin/core-frontend";
10
10
  import { createFileNameFromString, setupOutputFileLocation } from "./FilenameUtils.js";
11
11
  import { TestIModelBuilderImpl } from "./IModelBuilderImpl.js";
12
12
  export async function buildTestIModel(nameParam, cb) {
@@ -21,6 +21,32 @@ export async function buildTestIModel(nameParam, cb) {
21
21
  db.saveChanges("Created test IModel");
22
22
  db.close();
23
23
  }
24
- return SnapshotConnection.openFile(outputFile);
24
+ return TestIModelConnection.openFile(outputFile);
25
25
  }
26
+ /**
27
+ * Implementation of `IModelConnection` that allows opening local files in tests.
28
+ * @beta
29
+ */
30
+ /* c8 ignore start */
31
+ export class TestIModelConnection extends IModelConnection {
32
+ _db;
33
+ // This was added based on this: https://github.com/iTwin/itwinjs-core/pull/7171/files#diff-9d26b04e7ae074b911fb87be3425360d7bd55a7c9f947f5aed1ba36d359f01eb
34
+ constructor(_db) {
35
+ // eslint-disable-next-line @itwin/no-internal
36
+ super(_db.getConnectionProps());
37
+ this._db = _db;
38
+ IModelConnection.onOpen.raiseEvent(this);
39
+ }
40
+ get isClosed() {
41
+ // eslint-disable-next-line @itwin/no-internal
42
+ return !this._db.isOpen;
43
+ }
44
+ async close() {
45
+ this._db.close();
46
+ }
47
+ static openFile(filePath) {
48
+ return new TestIModelConnection(SnapshotDb.openFile(filePath));
49
+ }
50
+ }
51
+ /* c8 ignore end */
26
52
  //# sourceMappingURL=IModelUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAoB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AA8D/D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,uBAAuB,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACjD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module IModel\n */\n\nimport { SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./FilenameUtils.js\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl.js\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n /**\n * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<void>): Promise<IModelConnection> {\n const name = typeof nameParam === \"string\" ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(`${name}.bim`);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n"]}
1
+ {"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAY,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AA8D/D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAiC,EAAE,EAAwD;IAC/H,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,wBAAwB,CAAC,SAAS,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/G,MAAM,UAAU,GAAG,uBAAuB,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACtC,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;IACD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,qBAAqB;AACrB,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAE3B;IAD7B,4JAA4J;IAC5J,YAA6B,GAAa;QACxC,8CAA8C;QAC9C,KAAK,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,CAAC;QAFL,QAAG,GAAH,GAAG,CAAU;QAGxC,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,IAAoB,QAAQ;QAC1B,8CAA8C;QAC9C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,KAAK;QACzB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,QAAgB;QACrC,OAAO,IAAI,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjE,CAAC;CACF;AACD,mBAAmB","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 IModel\n */\n\nimport { IModelDb, SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps, RelationshipProps } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { createFileNameFromString, setupOutputFileLocation } from \"./FilenameUtils.js\";\nimport { TestIModelBuilderImpl } from \"./IModelBuilderImpl.js\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): Id64String;\n /**\n * Insert a relationship between two instances. The relationship is expected to be a subclass\n * of `BisCore:ElementRefersToElements` or `BisCore:ElementDrivesElement`.\n */\n insertRelationship<TProps extends RelationshipProps>(props: TProps): Id64String;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n /**\n * Import an ECSchema in a form of XML string into the builder's iModel.\n */\n importSchema(schemaXml: string): Promise<void>;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n * @deprecated in 4.x. Use an overload with `cb` returning a promise.\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param mochaContext Mocha context to generate iModel name from\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport async function buildTestIModel(mochaContext: Mocha.Context, cb: (builder: TestIModelBuilder) => Promise<void>): Promise<IModelConnection>;\nexport async function buildTestIModel(nameParam: string | Mocha.Context, cb: (builder: TestIModelBuilder) => void | Promise<void>): Promise<IModelConnection> {\n const name = typeof nameParam === \"string\" ? nameParam : createFileNameFromString(nameParam.test!.fullTitle());\n const outputFile = setupOutputFileLocation(`${name}.bim`);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new TestIModelBuilderImpl(db);\n try {\n await cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return TestIModelConnection.openFile(outputFile);\n}\n\n/**\n * Implementation of `IModelConnection` that allows opening local files in tests.\n * @beta\n */\n/* c8 ignore start */\nexport class TestIModelConnection extends IModelConnection {\n // This was added based on this: https://github.com/iTwin/itwinjs-core/pull/7171/files#diff-9d26b04e7ae074b911fb87be3425360d7bd55a7c9f947f5aed1ba36d359f01eb\n constructor(private readonly _db: IModelDb) {\n // eslint-disable-next-line @itwin/no-internal\n super(_db.getConnectionProps());\n IModelConnection.onOpen.raiseEvent(this);\n }\n\n public override get isClosed(): boolean {\n // eslint-disable-next-line @itwin/no-internal\n return !this._db.isOpen;\n }\n\n public override async close(): Promise<void> {\n this._db.close();\n }\n\n public static openFile(filePath: string): IModelConnection {\n return new TestIModelConnection(SnapshotDb.openFile(filePath));\n }\n}\n/* c8 ignore end */\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-testing",
3
- "version": "5.3.1",
3
+ "version": "5.4.0",
4
4
  "description": "Testing utilities for iTwin.js Presentation library",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,37 +32,37 @@
32
32
  "dependencies": {
33
33
  "rimraf": "^6.0.1",
34
34
  "sanitize-filename": "^1.6.3",
35
- "@itwin/presentation-components": "^5.10.0"
35
+ "@itwin/presentation-components": "^5.11.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@itwin/appui-abstract": "^4.1.0",
38
+ "@itwin/appui-abstract": "^4.1.0 || ^5.0.0",
39
39
  "@itwin/components-react": "^4.10.0 || ^5.0.0",
40
- "@itwin/core-backend": "^4.1.0",
41
- "@itwin/core-bentley": "^4.1.0",
42
- "@itwin/core-common": "^4.1.0",
43
- "@itwin/core-frontend": "^4.1.0",
44
- "@itwin/presentation-backend": "^4.1.0",
45
- "@itwin/presentation-common": "^4.1.0",
46
- "@itwin/presentation-frontend": "^4.1.0"
40
+ "@itwin/core-backend": "^4.1.0 || ^5.0.0",
41
+ "@itwin/core-bentley": "^4.1.0 || ^5.0.0",
42
+ "@itwin/core-common": "^4.1.0 || ^5.0.0",
43
+ "@itwin/core-frontend": "^4.1.0 || ^5.0.0",
44
+ "@itwin/presentation-backend": "^4.1.0 || ^5.0.0",
45
+ "@itwin/presentation-common": "^4.1.0 || ^5.0.0",
46
+ "@itwin/presentation-frontend": "^4.1.0 || ^5.0.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@itwin/appui-abstract": "^4.10.1",
49
+ "@itwin/appui-abstract": "^5.0.0-dev.49",
50
50
  "@itwin/build-tools": "^4.10.1",
51
- "@itwin/components-react": "^5.0.4",
52
- "@itwin/core-backend": "^4.10.1",
53
- "@itwin/core-bentley": "^4.10.1",
54
- "@itwin/core-common": "^4.10.1",
55
- "@itwin/core-frontend": "^4.10.1",
56
- "@itwin/core-geometry": "^4.10.1",
57
- "@itwin/core-orbitgt": "^4.10.1",
58
- "@itwin/core-quantity": "^4.10.1",
59
- "@itwin/core-react": "^5.0.4",
60
- "@itwin/ecschema-metadata": "^4.10.1",
51
+ "@itwin/components-react": "^5.1.0",
52
+ "@itwin/core-backend": "^5.0.0-dev.49",
53
+ "@itwin/core-bentley": "^5.0.0-dev.49",
54
+ "@itwin/core-common": "^5.0.0-dev.49",
55
+ "@itwin/core-frontend": "^5.0.0-dev.49",
56
+ "@itwin/core-geometry": "^5.0.0-dev.49",
57
+ "@itwin/core-orbitgt": "^5.0.0-dev.49",
58
+ "@itwin/core-quantity": "^5.0.0-dev.49",
59
+ "@itwin/core-react": "^5.1.0",
60
+ "@itwin/ecschema-metadata": "^5.0.0-dev.49",
61
61
  "@itwin/eslint-plugin": "5.0.0-dev.1",
62
- "@itwin/presentation-backend": "^4.10.1",
63
- "@itwin/presentation-common": "^4.10.1",
64
- "@itwin/presentation-frontend": "^4.10.1",
65
- "@itwin/webgl-compatibility": "^4.10.1",
62
+ "@itwin/presentation-backend": "^5.0.0-dev.49",
63
+ "@itwin/presentation-common": "^5.0.0-dev.49",
64
+ "@itwin/presentation-frontend": "^5.0.0-dev.49",
65
+ "@itwin/webgl-compatibility": "^5.0.0-dev.49",
66
66
  "@opentelemetry/api": "^1.9.0",
67
67
  "@types/chai": "^4.3.16",
68
68
  "@types/chai-as-promised": "^7.1.8",