@itwin/presentation-testing 3.0.0-dev.76 → 3.0.0-dev.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/{presentation-testing → cjs/presentation-testing}/ContentBuilder.d.ts +0 -0
  2. package/lib/cjs/presentation-testing/ContentBuilder.d.ts.map +1 -0
  3. package/lib/{presentation-testing → cjs/presentation-testing}/ContentBuilder.js +6 -35
  4. package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -0
  5. package/lib/{presentation-testing → cjs/presentation-testing}/Helpers.d.ts +0 -0
  6. package/lib/cjs/presentation-testing/Helpers.d.ts.map +1 -0
  7. package/lib/{presentation-testing → cjs/presentation-testing}/Helpers.js +2 -2
  8. package/lib/cjs/presentation-testing/Helpers.js.map +1 -0
  9. package/lib/{presentation-testing → cjs/presentation-testing}/HierarchyBuilder.d.ts +0 -0
  10. package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts.map +1 -0
  11. package/lib/{presentation-testing → cjs/presentation-testing}/HierarchyBuilder.js +2 -14
  12. package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -0
  13. package/lib/{presentation-testing.d.ts → cjs/presentation-testing.d.ts} +0 -0
  14. package/lib/cjs/presentation-testing.d.ts.map +1 -0
  15. package/lib/{presentation-testing.js → cjs/presentation-testing.js} +0 -0
  16. package/lib/cjs/presentation-testing.js.map +1 -0
  17. package/lib/esm/presentation-testing/ContentBuilder.d.ts +77 -0
  18. package/lib/esm/presentation-testing/ContentBuilder.d.ts.map +1 -0
  19. package/lib/esm/presentation-testing/ContentBuilder.js +120 -0
  20. package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -0
  21. package/lib/esm/presentation-testing/Helpers.d.ts +36 -0
  22. package/lib/esm/presentation-testing/Helpers.d.ts.map +1 -0
  23. package/lib/esm/presentation-testing/Helpers.js +103 -0
  24. package/lib/esm/presentation-testing/Helpers.js.map +1 -0
  25. package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +67 -0
  26. package/lib/esm/presentation-testing/HierarchyBuilder.d.ts.map +1 -0
  27. package/lib/esm/presentation-testing/HierarchyBuilder.js +64 -0
  28. package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -0
  29. package/lib/esm/presentation-testing.d.ts +22 -0
  30. package/lib/esm/presentation-testing.d.ts.map +1 -0
  31. package/lib/esm/presentation-testing.js +26 -0
  32. package/lib/esm/presentation-testing.js.map +1 -0
  33. package/package.json +23 -20
  34. package/lib/presentation-testing/ContentBuilder.d.ts.map +0 -1
  35. package/lib/presentation-testing/ContentBuilder.js.map +0 -1
  36. package/lib/presentation-testing/Helpers.d.ts.map +0 -1
  37. package/lib/presentation-testing/Helpers.js.map +0 -1
  38. package/lib/presentation-testing/HierarchyBuilder.d.ts.map +0 -1
  39. package/lib/presentation-testing/HierarchyBuilder.js.map +0 -1
  40. package/lib/presentation-testing.d.ts.map +0 -1
  41. package/lib/presentation-testing.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,OAAO,EAA8B,WAAW,EAAE,MAAM,EAAE,WAAW,EAAqB,OAAO,EAClG,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,qDAAqD;IACrD,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,yCAAyC;IACzC,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,sBAAsB;IACtB,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CAC/E;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,2BAA2B,CAAC;CAC5C;AAED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,aAAa,CAA0C;IAE/D;;;;OAIG;gBACS,KAAK,EAAE,mBAAmB;YAKxB,eAAe;IAa7B;;;;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,WAAW,GAAE,MAAgD;YAStI,eAAe;YAaf,uBAAuB;IA4BrC;;;;;;OAMG;IACU,4BAA4B,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;IAItI;;;;;;OAMG;IACU,gCAAgC,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;CAG3I"}
@@ -3,13 +3,6 @@
3
3
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
- var __asyncValues = (this && this.__asyncValues) || function (o) {
7
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
8
- var m = o[Symbol.asyncIterator], i;
9
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
10
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
11
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
12
- };
13
6
  Object.defineProperty(exports, "__esModule", { value: true });
14
7
  exports.ContentBuilder = void 0;
15
8
  /** @packageDocumentation
@@ -58,49 +51,27 @@ class ContentBuilder {
58
51
  });
59
52
  }
60
53
  async getECClassNames() {
61
- var e_1, _a;
62
54
  const rows = [];
63
- try {
64
- for (var _b = __asyncValues(this._iModel.query(`
55
+ for await (const row of this._iModel.query(`
65
56
  SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
66
57
  INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
67
58
  WHERE c.Modifier <> 1 AND c.Type = 0
68
59
  ORDER BY s.Name, c.Name
69
- `)), _c; _c = await _b.next(), !_c.done;) {
70
- const row = _c.value;
71
- rows.push(row);
72
- }
73
- }
74
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
- finally {
76
- try {
77
- if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
78
- }
79
- finally { if (e_1) throw e_1.error; }
60
+ `)) {
61
+ rows.push(row);
80
62
  }
81
63
  return rows;
82
64
  }
83
65
  async createContentForClasses(rulesetOrId, limitInstances, displayType) {
84
- var e_2, _a;
85
66
  const classNameEntries = await this.getECClassNames();
86
67
  const contents = [];
87
68
  for (const nameEntry of classNameEntries) {
88
69
  // try {
89
70
  const instanceIds = [];
90
- try {
91
- for (var _b = (e_2 = void 0, __asyncValues(this._iModel.query(`
71
+ for await (const row of this._iModel.query(`
92
72
  SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
93
- ORDER BY ECInstanceId`, undefined, limitInstances ? 1 : 4000))), _c; _c = await _b.next(), !_c.done;) {
94
- const row = _c.value;
95
- instanceIds.push(row);
96
- }
97
- }
98
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
99
- finally {
100
- try {
101
- if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
102
- }
103
- finally { if (e_2) throw e_2.error; }
73
+ ORDER BY ECInstanceId`, undefined, limitInstances ? 1 : 4000)) {
74
+ instanceIds.push(row);
104
75
  }
105
76
  if (!instanceIds.length)
106
77
  continue;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AACH,sDAA4C;AAE5C,oEAEoC;AACpC,4EAAmH;AACnH,wEAA4D;AAsC5D;;;GAGG;AACH,MAAa,cAAc;IAIzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAA2B,EAAE,WAAmB;QAC/F,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,6CAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAClJ,YAAY,CAAC,IAAI,GAAG,IAAI,4BAAM,CAAC,YAAY,CAAC,CAAC;QAE7C,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;QAChD,IAAI,CAAC,OAAO;YACV,OAAO,EAAE,CAAC;QAEZ,MAAM,WAAW,GAAG,IAAI,0BAA0B,EAAE,CAAC;QACrD,IAAA,qCAAe,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACtC,OAAO,WAAW,CAAC,OAAO,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,aAAa,CAAC,WAA6B,EAAE,YAA2B,EAAE,cAAsB,gDA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------\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\n/** @packageDocumentation\n * @module Content\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, RegisteredRuleset, Ruleset, traverseContent,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\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 /** Custom data provider that allows mocking data ContentBuilder receives */\n dataProvider?: IContentBuilderDataProvider;\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\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 }\n\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\n dataProvider.keys = new KeySet(instanceKeys);\n\n const content = await dataProvider.getContent();\n if (!content)\n return [];\n\n const accumulator = new PropertyRecordsAccumulator();\n traverseContent(accumulator, content);\n return accumulator.records;\n }\n\n /**\n * Create a list of property records using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param instanceKeys Keys of instances that should be queried.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\n });\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\n const rows = [];\n for await (const row of this._iModel.query(`\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\n WHERE c.Modifier <> 1 AND c.Type = 0\n ORDER BY s.Name, c.Name\n `)) {\n rows.push(row);\n }\n return rows;\n }\n\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\n const classNameEntries = await this.getECClassNames();\n\n const contents: ContentBuilderResult[] = [];\n\n for (const nameEntry of classNameEntries) {\n // try {\n const instanceIds = [];\n for await (const row of this._iModel.query(`\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId`, undefined, limitInstances ? 1 : 4000)) {\n instanceIds.push(row);\n }\n\n if (!instanceIds.length)\n continue;\n\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry.id } as InstanceKey));\n\n contents.push({\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\n });\n }\n\n return contents;\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes all of the class instances.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, false, displayType);\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes at most one class instance.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, true, displayType);\n }\n}\n\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\n private _records: PropertyRecord[] = [];\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n protected createRootPropertiesAppender() {\n return {\n append: (record: FieldHierarchyRecord) => {\n this._records.push(record.record);\n },\n };\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAErL,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAsBpI,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,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,wBAAwB;IACxB,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,qEA8BtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAuBrB,CAAC"}
@@ -53,7 +53,7 @@ function initializeRpcInterfaces(interfaces) {
53
53
  try {
54
54
  core_common_1.RpcConfiguration.initializeInterfaces(instance);
55
55
  }
56
- catch (_a) {
56
+ catch {
57
57
  // this may fail with "Error: RPC interface "xxx" is already initialized." because
58
58
  // multiple different tests want to set up rpc interfaces
59
59
  }
@@ -91,7 +91,7 @@ const initialize = async (props) => {
91
91
  activeLocale: core_frontend_1.IModelApp.localization.languageList()[0],
92
92
  },
93
93
  };
94
- await presentation_frontend_1.Presentation.initialize(Object.assign(Object.assign({}, defaultFrontendProps), props.frontendProps));
94
+ await presentation_frontend_1.Presentation.initialize({ ...defaultFrontendProps, ...props.frontendProps });
95
95
  isInitialized = true;
96
96
  };
97
97
  exports.initialize = initialize;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,+CAAiC;AACjC,kBAAkB;AAClB,sDAA2C;AAC3C,mBAAmB;AACnB,sDAAiD;AACjD,oBAAoB;AACpB,oDAE4B;AAC5B,wDAAgF;AAChF,sEAAqL;AAwB5K,mGAxBA,yCAAkB,OAwBA;AAAE,w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AEzC,qBAAqB;IACrB,oCAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC;AAvBW,QAAA,SAAS,aAuBpB","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 */\nimport * as rimraf from \"rimraf\";\n// common includes\nimport { Guid } from \"@itwin/core-bentley\";\n// backend includes\nimport { IModelHost } from \"@itwin/core-backend\";\n// frontend includes\nimport {\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\n} from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\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 RpcConfiguration.assign(definition, () => config);\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\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}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\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}\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 if (!props)\n props = {};\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 if (!props.backendProps.id)\n props.backendProps.id = `test-${Guid.createValue()}`;\n await IModelHost.startup();\n PresentationBackend.initialize(props.backendProps);\n\n // set up rpc interfaces\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init frontend\n if (!props.frontendApp)\n props.frontendApp = NoRenderApp;\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.languageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\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 // 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 // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory)\n rimraf.sync(hierarchiesCacheDirectory);\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HierarchyBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAqB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAG9E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IACjE,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,oBAAY,eAAe,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,UAAU,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAMpC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IAEnD,kBAAkB;gBACN,KAAK,EAAE,qBAAqB;YAK1B,kBAAkB;YAalB,iBAAiB;IAM/B;;;OAGG;IACU,eAAe,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAQtF"}
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.HierarchyBuilder = exports.defaultNodeMappingFunc = void 0;
15
4
  /*---------------------------------------------------------------------------------------------
@@ -21,7 +10,6 @@ exports.HierarchyBuilder = exports.defaultNodeMappingFunc = void 0;
21
10
  */
22
11
  const core_bentley_1 = require("@itwin/core-bentley");
23
12
  const presentation_components_1 = require("@itwin/presentation-components");
24
- const Utils_1 = require("@itwin/presentation-components/lib/presentation-components/tree/Utils");
25
13
  const presentation_frontend_1 = require("@itwin/presentation-frontend");
26
14
  /**
27
15
  * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
@@ -31,7 +19,7 @@ const defaultNodeMappingFunc = (node) => {
31
19
  // Skip properties 'id', 'parentId' as they contain internal stuff
32
20
  // that callers are most likely not interested in. Otherwise they can supply
33
21
  // a custom `NodeMappingFunc` that does return those properties as well.
34
- const { id, parentId } = node, resultNode = __rest(node, ["id", "parentId"]); // eslint-disable-line @typescript-eslint/no-unused-vars
22
+ const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
35
23
  return resultNode;
36
24
  };
37
25
  exports.defaultNodeMappingFunc = defaultNodeMappingFunc;
@@ -52,7 +40,7 @@ class HierarchyBuilder {
52
40
  const hierarchy = [];
53
41
  for (const node of nodes) {
54
42
  // istanbul ignore next: for some reason coverage tool thinks the below statement is conditional and one of branches is not covered...
55
- const _a = node, _b = Utils_1.PRESENTATION_TREE_NODE_KEY, key = _a[_b], nodeNoKey = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); // eslint-disable-line @typescript-eslint/no-unused-vars
43
+ const { [presentation_components_1.PRESENTATION_TREE_NODE_KEY]: key, ...nodeNoKey } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
56
44
  const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;
57
45
  const childNodes = await dataProvider.getNodes(node);
58
46
  if (childNodes.length > 0)
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HierarchyBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,sDAA4C;AAG5C,4EAA0G;AAC1G,wEAA4D;AA+B5D;;;GAGG;AACI,MAAM,sBAAsB,GAAoB,CAAC,IAAkB,EAAE,EAAE;IAC5E,mEAAmE;IACnE,4EAA4E;IAC5E,wEAAwE;IACxE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC,wDAAwD;IACtG,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AANW,QAAA,sBAAsB,0BAMjC;AAiBF;;;;;GAKG;AACH,MAAa,gBAAgB;IAI3B,kBAAkB;IAClB,YAAY,KAA4B;;QACtC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,MAAA,KAAK,CAAC,eAAe,mCAAI,8BAAsB,CAAC;IAC1E,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,KAAqB,EAAE,YAA0C;QAChG,MAAM,SAAS,GAAoB,EAAE,CAAC;QACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,sIAAsI;YACtI,MAAM,EAAE,CAAC,oDAA0B,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAI,IAA6D,CAAC,CAAC,wDAAwD;YACpL,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;gBACvB,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;SAC3F;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,SAAiB;QAC/C,MAAM,YAAY,GAAG,IAAI,sDAA4B,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACpG,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAC,WAA6B;QACxD,IAAI,OAAO,WAAW,KAAK,QAAQ;YACjC,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAE7C,OAAO,IAAA,oBAAK,EAAC,MAAM,oCAAY,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAA0B,EAAE,EAAE;YAC7G,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzCD,4CAyCC","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 Hierarchies\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { Omit, RegisteredRuleset, Ruleset } from \"@itwin/presentation-common\";\nimport { PRESENTATION_TREE_NODE_KEY, PresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeNodeItem } from \"@itwin/components-react\";\n\n/**\n * Structure that describes a Node with any indexed properties\n * except `children`.\n *\n * @public\n */\nexport interface MappedNode {\n /** Indexer for all properties in this data structure */\n [index: string]: any;\n /** Prohibited property */\n children?: never;\n}\n\n/**\n * Node in a hierarchy.\n * @public\n */\nexport interface HierarchyNode extends Omit<MappedNode, \"children\"> {\n /** Children of this node */\n children?: HierarchyNode[];\n}\n\n/**\n * A function that converts `TreeNodeItem` into a new custom object.\n * @public\n */\nexport type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;\n\n/**\n * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.\n * @public\n */\nexport const defaultNodeMappingFunc: NodeMappingFunc = (node: TreeNodeItem) => {\n // Skip properties 'id', 'parentId' as they contain internal stuff\n // that callers are most likely not interested in. Otherwise they can supply\n // a custom `NodeMappingFunc` that does return those properties as well.\n const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars\n return resultNode;\n};\n\n/**\n * Properties for creating a `HierarchyBuilder` instance.\n * @public\n */\nexport interface HierarchyBuilderProps {\n /** The iModel to pull data from */\n imodel: IModelConnection;\n /**\n * A function that maps node to something that the user of\n * this API is interested in. E.g. custom implementation may skip some unimportant\n * node properties to make resulting object smaller and easier to read.\n */\n nodeMappingFunc?: NodeMappingFunc;\n}\n\n/**\n * A class that constructs simple node hierarchy from specified\n * imodel and ruleset.\n *\n * @public\n */\nexport class HierarchyBuilder {\n private readonly _iModel: IModelConnection;\n private readonly _nodeMappingFunc: NodeMappingFunc;\n\n /** Constructor */\n constructor(props: HierarchyBuilderProps) {\n this._iModel = props.imodel;\n this._nodeMappingFunc = props.nodeMappingFunc ?? defaultNodeMappingFunc;\n }\n\n private async createSubHierarchy(nodes: TreeNodeItem[], dataProvider: PresentationTreeDataProvider) {\n const hierarchy: HierarchyNode[] = [];\n for (const node of nodes) {\n // istanbul ignore next: for some reason coverage tool thinks the below statement is conditional and one of branches is not covered...\n const { [PRESENTATION_TREE_NODE_KEY]: key, ...nodeNoKey } = (node as TreeNodeItem & { [PRESENTATION_TREE_NODE_KEY]: any }); // eslint-disable-line @typescript-eslint/no-unused-vars\n const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;\n const childNodes = await dataProvider.getNodes(node);\n if (childNodes.length > 0)\n hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);\n }\n return hierarchy;\n }\n\n private async doCreateHierarchy(rulesetId: string): Promise<HierarchyNode[]> {\n const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });\n const rootNodes = await dataProvider.getNodes();\n return this.createSubHierarchy(rootNodes, dataProvider);\n }\n\n /**\n * Create a hierarchy using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n */\n public async createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]> {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateHierarchy(rulesetOrId);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateHierarchy(ruleset.id);\n });\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C","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/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers\";\n"]}
@@ -0,0 +1,77 @@
1
+ import { IModelConnection } from "@itwin/core-frontend";
2
+ import { Content, InstanceKey, KeySet, PageOptions, Ruleset } from "@itwin/presentation-common";
3
+ import { PropertyRecord } from "@itwin/appui-abstract";
4
+ /**
5
+ * Interface for a data provider, which is used by ContentBuilder.
6
+ * @public
7
+ */
8
+ export interface IContentBuilderDataProvider {
9
+ /** Keys the data provider is creating content for */
10
+ keys: Readonly<KeySet>;
11
+ /** Get the size of content result set */
12
+ getContentSetSize: () => Promise<number>;
13
+ /** Get the content */
14
+ getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;
15
+ }
16
+ /**
17
+ * Property records grouped under a single className
18
+ * @public
19
+ */
20
+ export interface ContentBuilderResult {
21
+ /** Full name of ECClass whose records are contained in this data structure */
22
+ className: string;
23
+ /** Property records for the ECClass instance */
24
+ records: PropertyRecord[];
25
+ }
26
+ /**
27
+ * Properties for creating a `ContentBuilder` instance.
28
+ * @public
29
+ */
30
+ export interface ContentBuilderProps {
31
+ /** The iModel to pull data from */
32
+ imodel: IModelConnection;
33
+ /** Custom data provider that allows mocking data ContentBuilder receives */
34
+ dataProvider?: IContentBuilderDataProvider;
35
+ }
36
+ /**
37
+ * A class that constructs content from specified imodel and ruleset.
38
+ * @public
39
+ */
40
+ export declare class ContentBuilder {
41
+ private readonly _iModel;
42
+ private _dataProvider;
43
+ /**
44
+ * Constructor
45
+ * @param iModel
46
+ * @param dataProvider
47
+ */
48
+ constructor(props: ContentBuilderProps);
49
+ private doCreateContent;
50
+ /**
51
+ * Create a list of property records using the supplied presentation ruleset.
52
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
53
+ * @param instanceKeys Keys of instances that should be queried.
54
+ * @param displayType Type of content container display. For example:
55
+ * "PropertyPane", "Grid", "List" etc.
56
+ */
57
+ createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType?: string): Promise<PropertyRecord[]>;
58
+ private getECClassNames;
59
+ private createContentForClasses;
60
+ /**
61
+ * Create a list of grouped property records using the supplied presentation ruleset.
62
+ * Each group includes all of the class instances.
63
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
64
+ * @param displayType Type of content container display. For example:
65
+ * "PropertyPane", "Grid", "List" etc.
66
+ */
67
+ createContentForAllInstances(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
68
+ /**
69
+ * Create a list of grouped property records using the supplied presentation ruleset.
70
+ * Each group includes at most one class instance.
71
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
72
+ * @param displayType Type of content container display. For example:
73
+ * "PropertyPane", "Grid", "List" etc.
74
+ */
75
+ createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
76
+ }
77
+ //# sourceMappingURL=ContentBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE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,OAAO,GAAG,MAAM,EAAE,WAAW,GAAE,MAAgD;CAG3I"}
@@ -0,0 +1,120 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Content
7
+ */
8
+ import { using } from "@itwin/core-bentley";
9
+ import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
10
+ import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
11
+ import { Presentation } from "@itwin/presentation-frontend";
12
+ /**
13
+ * A class that constructs content from specified imodel and ruleset.
14
+ * @public
15
+ */
16
+ export class ContentBuilder {
17
+ /**
18
+ * Constructor
19
+ * @param iModel
20
+ * @param dataProvider
21
+ */
22
+ constructor(props) {
23
+ this._iModel = props.imodel;
24
+ this._dataProvider = props.dataProvider;
25
+ }
26
+ async doCreateContent(rulesetId, instanceKeys, displayType) {
27
+ const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
28
+ dataProvider.keys = new KeySet(instanceKeys);
29
+ const content = await dataProvider.getContent();
30
+ if (!content)
31
+ return [];
32
+ const accumulator = new PropertyRecordsAccumulator();
33
+ traverseContent(accumulator, content);
34
+ return accumulator.records;
35
+ }
36
+ /**
37
+ * Create a list of property records using the supplied presentation ruleset.
38
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
39
+ * @param instanceKeys Keys of instances that should be queried.
40
+ * @param displayType Type of content container display. For example:
41
+ * "PropertyPane", "Grid", "List" etc.
42
+ */
43
+ async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
44
+ if (typeof rulesetOrId === "string")
45
+ return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
46
+ return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
47
+ return this.doCreateContent(ruleset.id, instanceKeys, displayType);
48
+ });
49
+ }
50
+ async getECClassNames() {
51
+ const rows = [];
52
+ for await (const row of this._iModel.query(`
53
+ SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
54
+ INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
55
+ WHERE c.Modifier <> 1 AND c.Type = 0
56
+ ORDER BY s.Name, c.Name
57
+ `)) {
58
+ rows.push(row);
59
+ }
60
+ return rows;
61
+ }
62
+ async createContentForClasses(rulesetOrId, limitInstances, displayType) {
63
+ const classNameEntries = await this.getECClassNames();
64
+ const contents = [];
65
+ for (const nameEntry of classNameEntries) {
66
+ // try {
67
+ const instanceIds = [];
68
+ for await (const row of this._iModel.query(`
69
+ SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
70
+ ORDER BY ECInstanceId`, undefined, limitInstances ? 1 : 4000)) {
71
+ instanceIds.push(row);
72
+ }
73
+ if (!instanceIds.length)
74
+ continue;
75
+ const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry.id }));
76
+ contents.push({
77
+ className: `${nameEntry.schemaName}:${nameEntry.className}`,
78
+ records: await this.createContent(rulesetOrId, instanceKeys, displayType),
79
+ });
80
+ }
81
+ return contents;
82
+ }
83
+ /**
84
+ * Create a list of grouped property records using the supplied presentation ruleset.
85
+ * Each group includes all of the class instances.
86
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
87
+ * @param displayType Type of content container display. For example:
88
+ * "PropertyPane", "Grid", "List" etc.
89
+ */
90
+ async createContentForAllInstances(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
91
+ return this.createContentForClasses(rulesetOrId, false, displayType);
92
+ }
93
+ /**
94
+ * Create a list of grouped property records using the supplied presentation ruleset.
95
+ * Each group includes at most one class instance.
96
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
97
+ * @param displayType Type of content container display. For example:
98
+ * "PropertyPane", "Grid", "List" etc.
99
+ */
100
+ async createContentForInstancePerClass(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
101
+ return this.createContentForClasses(rulesetOrId, true, displayType);
102
+ }
103
+ }
104
+ class PropertyRecordsAccumulator extends PropertyRecordsBuilder {
105
+ constructor() {
106
+ super(...arguments);
107
+ this._records = [];
108
+ }
109
+ get records() {
110
+ return this._records;
111
+ }
112
+ createRootPropertiesAppender() {
113
+ return {
114
+ append: (record) => {
115
+ this._records.push(record.record);
116
+ },
117
+ };
118
+ }
119
+ }
120
+ //# sourceMappingURL=ContentBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EACI,0BAA0B,EAAe,MAAM,EAA2C,eAAe,GACnH,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAwB,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAsC5D;;;GAGG;AACH,MAAM,OAAO,cAAc;IAIzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAA2B,EAAE,WAAmB;QAC/F,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW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,WAAW,CAAC,CAAC;IACtE,CAAC;CACF;AAED,MAAM,0BAA2B,SAAQ,sBAAsB;IAA/D;;QACU,aAAQ,GAAqB,EAAE,CAAC;IAa1C,CAAC;IAXC,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAES,4BAA4B;QACpC,OAAO;YACL,MAAM,EAAE,CAAC,MAA4B,EAAE,EAAE;gBACvC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC;SACF,CAAC;IACJ,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\n/** @packageDocumentation\n * @module Content\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, RegisteredRuleset, Ruleset, traverseContent,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\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 /** Custom data provider that allows mocking data ContentBuilder receives */\n dataProvider?: IContentBuilderDataProvider;\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\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 }\n\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\n dataProvider.keys = new KeySet(instanceKeys);\n\n const content = await dataProvider.getContent();\n if (!content)\n return [];\n\n const accumulator = new PropertyRecordsAccumulator();\n traverseContent(accumulator, content);\n return accumulator.records;\n }\n\n /**\n * Create a list of property records using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param instanceKeys Keys of instances that should be queried.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\n });\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\n const rows = [];\n for await (const row of this._iModel.query(`\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\n WHERE c.Modifier <> 1 AND c.Type = 0\n ORDER BY s.Name, c.Name\n `)) {\n rows.push(row);\n }\n return rows;\n }\n\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\n const classNameEntries = await this.getECClassNames();\n\n const contents: ContentBuilderResult[] = [];\n\n for (const nameEntry of classNameEntries) {\n // try {\n const instanceIds = [];\n for await (const row of this._iModel.query(`\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId`, undefined, limitInstances ? 1 : 4000)) {\n instanceIds.push(row);\n }\n\n if (!instanceIds.length)\n continue;\n\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry.id } as InstanceKey));\n\n contents.push({\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\n });\n }\n\n return contents;\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes all of the class instances.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, false, displayType);\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes at most one class instance.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, true, displayType);\n }\n}\n\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\n private _records: PropertyRecord[] = [];\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n protected createRootPropertiesAppender() {\n return {\n append: (record: FieldHierarchyRecord) => {\n this._records.push(record.record);\n },\n };\n }\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
2
+ import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
3
+ import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
4
+ export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
5
+ /** @public */
6
+ export interface PresentationTestingInitProps {
7
+ /** Properties for backend initialization */
8
+ backendProps?: PresentationBackendProps;
9
+ /** Properties for frontend initialization */
10
+ frontendProps?: PresentationFrontendProps;
11
+ /** IModelApp implementation */
12
+ frontendApp?: {
13
+ startup: (opts?: IModelAppOptions) => Promise<void>;
14
+ };
15
+ /** IModelApp options */
16
+ frontendAppOptions?: IModelAppOptions;
17
+ }
18
+ /**
19
+ * Initialize the framework for presentation testing. The function sets up backend,
20
+ * frontend and RPC communication between them.
21
+ *
22
+ * @see `terminate`
23
+ *
24
+ * @public
25
+ */
26
+ export declare const initialize: (props?: PresentationTestingInitProps | undefined) => Promise<void>;
27
+ /**
28
+ * Undoes the setup made by `initialize`.
29
+ * @param frontendApp IModelApp implementation
30
+ *
31
+ * @see `initialize`
32
+ *
33
+ * @public
34
+ */
35
+ export declare const terminate: (frontendApp?: typeof IModelApp) => Promise<void>;
36
+ //# sourceMappingURL=Helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAErL,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAsBpI,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,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,wBAAwB;IACxB,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,qEA8BtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAuBrB,CAAC"}
@@ -0,0 +1,103 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Helpers
7
+ */
8
+ import * as rimraf from "rimraf";
9
+ // common includes
10
+ import { Guid } from "@itwin/core-bentley";
11
+ // backend includes
12
+ import { IModelHost } from "@itwin/core-backend";
13
+ // frontend includes
14
+ import { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, SnapshotIModelRpcInterface, } from "@itwin/core-common";
15
+ import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
16
+ import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerMode } from "@itwin/presentation-backend";
17
+ import { PresentationRpcInterface } from "@itwin/presentation-common";
18
+ import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
19
+ function initializeRpcInterfaces(interfaces) {
20
+ const config = class extends RpcDefaultConfiguration {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.interfaces = () => interfaces;
24
+ }
25
+ };
26
+ for (const definition of interfaces)
27
+ RpcConfiguration.assign(definition, () => config);
28
+ const instance = RpcConfiguration.obtain(config);
29
+ try {
30
+ RpcConfiguration.initializeInterfaces(instance);
31
+ }
32
+ catch {
33
+ // this may fail with "Error: RPC interface "xxx" is already initialized." because
34
+ // multiple different tests want to set up rpc interfaces
35
+ }
36
+ }
37
+ let isInitialized = false;
38
+ export { HierarchyCacheMode, PresentationManagerMode };
39
+ /**
40
+ * Initialize the framework for presentation testing. The function sets up backend,
41
+ * frontend and RPC communication between them.
42
+ *
43
+ * @see `terminate`
44
+ *
45
+ * @public
46
+ */
47
+ export const initialize = async (props) => {
48
+ var _a;
49
+ if (isInitialized)
50
+ return;
51
+ if (!props)
52
+ props = {};
53
+ // init backend
54
+ // make sure backend gets assigned an id which puts its resources into a unique directory
55
+ props.backendProps = (_a = props.backendProps) !== null && _a !== void 0 ? _a : {};
56
+ if (!props.backendProps.id)
57
+ props.backendProps.id = `test-${Guid.createValue()}`;
58
+ await IModelHost.startup();
59
+ PresentationBackend.initialize(props.backendProps);
60
+ // set up rpc interfaces
61
+ initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
62
+ // init frontend
63
+ if (!props.frontendApp)
64
+ props.frontendApp = NoRenderApp;
65
+ await props.frontendApp.startup(props.frontendAppOptions);
66
+ const defaultFrontendProps = {
67
+ presentation: {
68
+ activeLocale: IModelApp.localization.languageList()[0],
69
+ },
70
+ };
71
+ await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });
72
+ isInitialized = true;
73
+ };
74
+ /**
75
+ * Undoes the setup made by `initialize`.
76
+ * @param frontendApp IModelApp implementation
77
+ *
78
+ * @see `initialize`
79
+ *
80
+ * @public
81
+ */
82
+ export const terminate = async (frontendApp = IModelApp) => {
83
+ var _a, _b, _c;
84
+ if (!isInitialized)
85
+ return;
86
+ // store directory that needs to be cleaned-up
87
+ let hierarchiesCacheDirectory;
88
+ const hierarchiesCacheConfig = (_b = (_a = PresentationBackend.initProps) === null || _a === void 0 ? void 0 : _a.caching) === null || _b === void 0 ? void 0 : _b.hierarchies;
89
+ if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Disk)
90
+ hierarchiesCacheDirectory = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.directory;
91
+ else if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Hybrid)
92
+ hierarchiesCacheDirectory = (_c = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.disk) === null || _c === void 0 ? void 0 : _c.directory;
93
+ // terminate backend
94
+ PresentationBackend.terminate();
95
+ await IModelHost.shutdown();
96
+ if (hierarchiesCacheDirectory)
97
+ rimraf.sync(hierarchiesCacheDirectory);
98
+ // terminate frontend
99
+ PresentationFrontend.terminate();
100
+ await frontendApp.shutdown();
101
+ isInitialized = false;
102
+ };
103
+ //# sourceMappingURL=Helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,kBAAkB;AAClB,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,mBAAmB;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,oBAAoB;AACpB,OAAO,EACL,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAA0B,0BAA0B,GACtH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,YAAY,IAAI,mBAAmB,EAAwD,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACrL,OAAO,EAAE,wBAAwB,EAAE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IAC5B,IAAI,yBAAyB;QAC3B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAEzC,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 */\nimport * as rimraf from \"rimraf\";\n// common includes\nimport { Guid } from \"@itwin/core-bentley\";\n// backend includes\nimport { IModelHost } from \"@itwin/core-backend\";\n// frontend includes\nimport {\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\n} from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\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 RpcConfiguration.assign(definition, () => config);\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\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}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\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}\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 if (!props)\n props = {};\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 if (!props.backendProps.id)\n props.backendProps.id = `test-${Guid.createValue()}`;\n await IModelHost.startup();\n PresentationBackend.initialize(props.backendProps);\n\n // set up rpc interfaces\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init frontend\n if (!props.frontendApp)\n props.frontendApp = NoRenderApp;\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.languageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\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 // 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 // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory)\n rimraf.sync(hierarchiesCacheDirectory);\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
@@ -0,0 +1,67 @@
1
+ import { IModelConnection } from "@itwin/core-frontend";
2
+ import { Omit, Ruleset } from "@itwin/presentation-common";
3
+ import { TreeNodeItem } from "@itwin/components-react";
4
+ /**
5
+ * Structure that describes a Node with any indexed properties
6
+ * except `children`.
7
+ *
8
+ * @public
9
+ */
10
+ export interface MappedNode {
11
+ /** Indexer for all properties in this data structure */
12
+ [index: string]: any;
13
+ /** Prohibited property */
14
+ children?: never;
15
+ }
16
+ /**
17
+ * Node in a hierarchy.
18
+ * @public
19
+ */
20
+ export interface HierarchyNode extends Omit<MappedNode, "children"> {
21
+ /** Children of this node */
22
+ children?: HierarchyNode[];
23
+ }
24
+ /**
25
+ * A function that converts `TreeNodeItem` into a new custom object.
26
+ * @public
27
+ */
28
+ export declare type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;
29
+ /**
30
+ * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
31
+ * @public
32
+ */
33
+ export declare const defaultNodeMappingFunc: NodeMappingFunc;
34
+ /**
35
+ * Properties for creating a `HierarchyBuilder` instance.
36
+ * @public
37
+ */
38
+ export interface HierarchyBuilderProps {
39
+ /** The iModel to pull data from */
40
+ imodel: IModelConnection;
41
+ /**
42
+ * A function that maps node to something that the user of
43
+ * this API is interested in. E.g. custom implementation may skip some unimportant
44
+ * node properties to make resulting object smaller and easier to read.
45
+ */
46
+ nodeMappingFunc?: NodeMappingFunc;
47
+ }
48
+ /**
49
+ * A class that constructs simple node hierarchy from specified
50
+ * imodel and ruleset.
51
+ *
52
+ * @public
53
+ */
54
+ export declare class HierarchyBuilder {
55
+ private readonly _iModel;
56
+ private readonly _nodeMappingFunc;
57
+ /** Constructor */
58
+ constructor(props: HierarchyBuilderProps);
59
+ private createSubHierarchy;
60
+ private doCreateHierarchy;
61
+ /**
62
+ * Create a hierarchy using the supplied presentation ruleset.
63
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
64
+ */
65
+ createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]>;
66
+ }
67
+ //# sourceMappingURL=HierarchyBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HierarchyBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAqB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAG9E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IACjE,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,oBAAY,eAAe,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,UAAU,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAMpC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IAEnD,kBAAkB;gBACN,KAAK,EAAE,qBAAqB;YAK1B,kBAAkB;YAalB,iBAAiB;IAM/B;;;OAGG;IACU,eAAe,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAQtF"}
@@ -0,0 +1,64 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Hierarchies
7
+ */
8
+ import { using } from "@itwin/core-bentley";
9
+ import { PRESENTATION_TREE_NODE_KEY, PresentationTreeDataProvider } from "@itwin/presentation-components";
10
+ import { Presentation } from "@itwin/presentation-frontend";
11
+ /**
12
+ * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
13
+ * @public
14
+ */
15
+ export const defaultNodeMappingFunc = (node) => {
16
+ // Skip properties 'id', 'parentId' as they contain internal stuff
17
+ // that callers are most likely not interested in. Otherwise they can supply
18
+ // a custom `NodeMappingFunc` that does return those properties as well.
19
+ const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
20
+ return resultNode;
21
+ };
22
+ /**
23
+ * A class that constructs simple node hierarchy from specified
24
+ * imodel and ruleset.
25
+ *
26
+ * @public
27
+ */
28
+ export class HierarchyBuilder {
29
+ /** Constructor */
30
+ constructor(props) {
31
+ var _a;
32
+ this._iModel = props.imodel;
33
+ this._nodeMappingFunc = (_a = props.nodeMappingFunc) !== null && _a !== void 0 ? _a : defaultNodeMappingFunc;
34
+ }
35
+ async createSubHierarchy(nodes, dataProvider) {
36
+ const hierarchy = [];
37
+ for (const node of nodes) {
38
+ // istanbul ignore next: for some reason coverage tool thinks the below statement is conditional and one of branches is not covered...
39
+ const { [PRESENTATION_TREE_NODE_KEY]: key, ...nodeNoKey } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
40
+ const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;
41
+ const childNodes = await dataProvider.getNodes(node);
42
+ if (childNodes.length > 0)
43
+ hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);
44
+ }
45
+ return hierarchy;
46
+ }
47
+ async doCreateHierarchy(rulesetId) {
48
+ const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });
49
+ const rootNodes = await dataProvider.getNodes();
50
+ return this.createSubHierarchy(rootNodes, dataProvider);
51
+ }
52
+ /**
53
+ * Create a hierarchy using the supplied presentation ruleset.
54
+ * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
55
+ */
56
+ async createHierarchy(rulesetOrId) {
57
+ if (typeof rulesetOrId === "string")
58
+ return this.doCreateHierarchy(rulesetOrId);
59
+ return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
60
+ return this.doCreateHierarchy(ruleset.id);
61
+ });
62
+ }
63
+ }
64
+ //# sourceMappingURL=HierarchyBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HierarchyBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AA+B5D;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAoB,CAAC,IAAkB,EAAE,EAAE;IAC5E,mEAAmE;IACnE,4EAA4E;IAC5E,wEAAwE;IACxE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC,wDAAwD;IACtG,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAiBF;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAI3B,kBAAkB;IAClB,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AW,CAAC,CAAC;QAE7C,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAA0B,EAAE,EAAE;YAC7G,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,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 Hierarchies\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { Omit, RegisteredRuleset, Ruleset } from \"@itwin/presentation-common\";\nimport { PRESENTATION_TREE_NODE_KEY, PresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeNodeItem } from \"@itwin/components-react\";\n\n/**\n * Structure that describes a Node with any indexed properties\n * except `children`.\n *\n * @public\n */\nexport interface MappedNode {\n /** Indexer for all properties in this data structure */\n [index: string]: any;\n /** Prohibited property */\n children?: never;\n}\n\n/**\n * Node in a hierarchy.\n * @public\n */\nexport interface HierarchyNode extends Omit<MappedNode, \"children\"> {\n /** Children of this node */\n children?: HierarchyNode[];\n}\n\n/**\n * A function that converts `TreeNodeItem` into a new custom object.\n * @public\n */\nexport type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;\n\n/**\n * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.\n * @public\n */\nexport const defaultNodeMappingFunc: NodeMappingFunc = (node: TreeNodeItem) => {\n // Skip properties 'id', 'parentId' as they contain internal stuff\n // that callers are most likely not interested in. Otherwise they can supply\n // a custom `NodeMappingFunc` that does return those properties as well.\n const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars\n return resultNode;\n};\n\n/**\n * Properties for creating a `HierarchyBuilder` instance.\n * @public\n */\nexport interface HierarchyBuilderProps {\n /** The iModel to pull data from */\n imodel: IModelConnection;\n /**\n * A function that maps node to something that the user of\n * this API is interested in. E.g. custom implementation may skip some unimportant\n * node properties to make resulting object smaller and easier to read.\n */\n nodeMappingFunc?: NodeMappingFunc;\n}\n\n/**\n * A class that constructs simple node hierarchy from specified\n * imodel and ruleset.\n *\n * @public\n */\nexport class HierarchyBuilder {\n private readonly _iModel: IModelConnection;\n private readonly _nodeMappingFunc: NodeMappingFunc;\n\n /** Constructor */\n constructor(props: HierarchyBuilderProps) {\n this._iModel = props.imodel;\n this._nodeMappingFunc = props.nodeMappingFunc ?? defaultNodeMappingFunc;\n }\n\n private async createSubHierarchy(nodes: TreeNodeItem[], dataProvider: PresentationTreeDataProvider) {\n const hierarchy: HierarchyNode[] = [];\n for (const node of nodes) {\n // istanbul ignore next: for some reason coverage tool thinks the below statement is conditional and one of branches is not covered...\n const { [PRESENTATION_TREE_NODE_KEY]: key, ...nodeNoKey } = (node as TreeNodeItem & { [PRESENTATION_TREE_NODE_KEY]: any }); // eslint-disable-line @typescript-eslint/no-unused-vars\n const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;\n const childNodes = await dataProvider.getNodes(node);\n if (childNodes.length > 0)\n hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);\n }\n return hierarchy;\n }\n\n private async doCreateHierarchy(rulesetId: string): Promise<HierarchyNode[]> {\n const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });\n const rootNodes = await dataProvider.getNodes();\n return this.createSubHierarchy(rootNodes, dataProvider);\n }\n\n /**\n * Create a hierarchy using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n */\n public async createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]> {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateHierarchy(rulesetOrId);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateHierarchy(ruleset.id);\n });\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module Hierarchies
3
+ *
4
+ * @docs-group-description Hierarchies
5
+ * Types for testing hierarchies.
6
+ */
7
+ export * from "./presentation-testing/HierarchyBuilder";
8
+ /**
9
+ * @module Content
10
+ *
11
+ * @docs-group-description Content
12
+ * Types for testing content.
13
+ */
14
+ export * from "./presentation-testing/ContentBuilder";
15
+ /**
16
+ * @module Helpers
17
+ *
18
+ * @docs-group-description Helpers
19
+ * Various test helpers.
20
+ */
21
+ export * from "./presentation-testing/Helpers";
22
+ //# sourceMappingURL=presentation-testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /**
6
+ * @module Hierarchies
7
+ *
8
+ * @docs-group-description Hierarchies
9
+ * Types for testing hierarchies.
10
+ */
11
+ export * from "./presentation-testing/HierarchyBuilder";
12
+ /**
13
+ * @module Content
14
+ *
15
+ * @docs-group-description Content
16
+ * Types for testing content.
17
+ */
18
+ export * from "./presentation-testing/ContentBuilder";
19
+ /**
20
+ * @module Helpers
21
+ *
22
+ * @docs-group-description Helpers
23
+ * Various test helpers.
24
+ */
25
+ export * from "./presentation-testing/Helpers";
26
+ //# sourceMappingURL=presentation-testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,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/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-testing",
3
- "version": "3.0.0-dev.76",
3
+ "version": "3.0.0-dev.80",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,27 +17,28 @@
17
17
  "name": "Bentley Systems, Inc.",
18
18
  "url": "http://www.bentley.com"
19
19
  },
20
- "main": "lib/presentation-testing.js",
21
- "typings": "lib/presentation-testing",
20
+ "main": "lib/cjs/presentation-testing.js",
21
+ "module": "lib/esm/presentation-testing.js",
22
+ "typings": "lib/cjs/presentation-testing",
22
23
  "devDependencies": {
23
24
  "cpx": "^1.5.0",
24
25
  "ignore-styles": "^5.0.1"
25
26
  },
26
27
  "dependencies": {
27
- "@bentley/backend-itwin-client": "3.0.0-dev.76",
28
- "@itwin/core-bentley": "3.0.0-dev.76",
29
- "@itwin/build-tools": "3.0.0-dev.76",
30
- "@itwin/eslint-plugin": "3.0.0-dev.76",
31
- "@itwin/core-backend": "3.0.0-dev.76",
32
- "@itwin/core-common": "3.0.0-dev.76",
33
- "@itwin/core-frontend": "3.0.0-dev.76",
34
- "@bentley/itwin-client": "3.0.0-dev.76",
35
- "@itwin/presentation-backend": "3.0.0-dev.76",
36
- "@itwin/presentation-common": "3.0.0-dev.76",
37
- "@itwin/presentation-components": "3.0.0-dev.76",
38
- "@itwin/presentation-frontend": "3.0.0-dev.76",
39
- "@itwin/appui-abstract": "3.0.0-dev.76",
40
- "@itwin/components-react": "3.0.0-dev.76",
28
+ "@bentley/backend-itwin-client": "3.0.0-dev.80",
29
+ "@itwin/core-bentley": "3.0.0-dev.80",
30
+ "@itwin/build-tools": "3.0.0-dev.80",
31
+ "@itwin/eslint-plugin": "3.0.0-dev.80",
32
+ "@itwin/core-backend": "3.0.0-dev.80",
33
+ "@itwin/core-common": "3.0.0-dev.80",
34
+ "@itwin/core-frontend": "3.0.0-dev.80",
35
+ "@bentley/itwin-client": "3.0.0-dev.80",
36
+ "@itwin/presentation-backend": "3.0.0-dev.80",
37
+ "@itwin/presentation-common": "3.0.0-dev.80",
38
+ "@itwin/presentation-components": "3.0.0-dev.80",
39
+ "@itwin/presentation-frontend": "3.0.0-dev.80",
40
+ "@itwin/appui-abstract": "3.0.0-dev.80",
41
+ "@itwin/components-react": "3.0.0-dev.80",
41
42
  "@types/chai": "^4.1.4",
42
43
  "@types/chai-as-promised": "^7",
43
44
  "@types/chai-jest-snapshot": "^1.3.0",
@@ -80,8 +81,10 @@
80
81
  },
81
82
  "scripts": {
82
83
  "compile": "npm run -s build",
83
- "build": "npm run -s extract && tsc 1>&2",
84
- "build:watch": "tsc -w",
84
+ "build": "npm run -s build:cjs && npm run -s build:esm",
85
+ "build:cjs": "tsc -p tsconfig.cjs.json",
86
+ "build:esm": "tsc -p tsconfig.esm.json",
87
+ "build:watch": "npm run -s build:cjs -- -w",
85
88
  "clean": "rimraf lib .rush/temp/package-deps*.json",
86
89
  "cover": "nyc npm -s test",
87
90
  "docs": "npm run -s docs:reference && npm run -s docs:changelog",
@@ -90,6 +93,6 @@
90
93
  "extract": "betools extract --fileExt=ts --extractFrom=./src/test --recursive --out=../../generated-docs/extract",
91
94
  "extract-api": "betools extract-api --entry=presentation-testing",
92
95
  "lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2",
93
- "test": "mocha -r ignore-styles -r jsdom-global/register --config ../.mocharc.json \"./lib/test/**/*.test.js\""
96
+ "test": "mocha -r ignore-styles -r jsdom-global/register --config ../.mocharc.json \"./lib/cjs/test/**/*.test.js\""
94
97
  }
95
98
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContentBuilder.d.ts","sourceRoot":"","sources":["../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,OAAO,EAA8B,WAAW,EAAE,MAAM,EAAE,WAAW,EAAqB,OAAO,EAClG,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,qDAAqD;IACrD,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,yCAAyC;IACzC,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,sBAAsB;IACtB,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;CAC/E;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,2BA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AAI,CAAC,uBAAuB,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACtE,CAAC;CACF;AAzGD,wCAyGC;AAED,MAAM,0BAA2B,SAAQ,gDAAsB;IAA/D;;QACU,aAAQ,GAAqB,EAAE,CAAC;IAa1C,CAAC;IAXC,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAES,4BAA4B;QACpC,OAAO;YACL,MAAM,EAAE,CAAC,MAA4B,EAAE,EAAE;gBACvC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC;SACF,CAAC;IACJ,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\n/** @packageDocumentation\n * @module Content\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, RegisteredRuleset, Ruleset, traverseContent,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\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 /** Custom data provider that allows mocking data ContentBuilder receives */\n dataProvider?: IContentBuilderDataProvider;\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\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 }\n\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\n dataProvider.keys = new KeySet(instanceKeys);\n\n const content = await dataProvider.getContent();\n if (!content)\n return [];\n\n const accumulator = new PropertyRecordsAccumulator();\n traverseContent(accumulator, content);\n return accumulator.records;\n }\n\n /**\n * Create a list of property records using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param instanceKeys Keys of instances that should be queried.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\n });\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\n const rows = [];\n for await (const row of this._iModel.query(`\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\n WHERE c.Modifier <> 1 AND c.Type = 0\n ORDER BY s.Name, c.Name\n `)) {\n rows.push(row);\n }\n return rows;\n }\n\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\n const classNameEntries = await this.getECClassNames();\n\n const contents: ContentBuilderResult[] = [];\n\n for (const nameEntry of classNameEntries) {\n // try {\n const instanceIds = [];\n for await (const row of this._iModel.query(`\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId`, undefined, limitInstances ? 1 : 4000)) {\n instanceIds.push(row);\n }\n\n if (!instanceIds.length)\n continue;\n\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry.id } as InstanceKey));\n\n contents.push({\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\n });\n }\n\n return contents;\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes all of the class instances.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, false, displayType);\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes at most one class instance.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, true, displayType);\n }\n}\n\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\n private _records: PropertyRecord[] = [];\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n protected createRootPropertiesAppender() {\n return {\n append: (record: FieldHierarchyRecord) => {\n this._records.push(record.record);\n },\n };\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAErL,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAsBpI,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,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,wBAAwB;IACxB,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,qEA8BtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAuBrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,+CAAiC;AACjC,kBAAkB;AAClB,sDAA2C;AAC3C,mBAAmB;AACnB,sDAAiD;AACjD,oBAAoB;AACpB,oDAE4B;AAC5B,wDAAgF;AAChF,sEAAqL;AAwB5K,mGAxBA,yCAAkB,OAwBA;AAAE,wGAx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B,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC;AAvBW,QAAA,SAAS,aAuBpB","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 */\nimport * as rimraf from \"rimraf\";\n// common includes\nimport { Guid } from \"@itwin/core-bentley\";\n// backend includes\nimport { IModelHost } from \"@itwin/core-backend\";\n// frontend includes\nimport {\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\n} from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\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 RpcConfiguration.assign(definition, () => config);\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\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}\n\nlet isInitialized = false;\n\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\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}\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 if (!props)\n props = {};\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 if (!props.backendProps.id)\n props.backendProps.id = `test-${Guid.createValue()}`;\n await IModelHost.startup();\n PresentationBackend.initialize(props.backendProps);\n\n // set up rpc interfaces\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init frontend\n if (!props.frontendApp)\n props.frontendApp = NoRenderApp;\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.languageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\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 // 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 // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory)\n rimraf.sync(hierarchiesCacheDirectory);\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"HierarchyBuilder.d.ts","sourceRoot":"","sources":["../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAqB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAI9E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IACjE,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,oBAAY,eAAe,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,UAAU,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAMpC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IAEnD,kBAAkB;gBACN,KAAK,EAAE,qBAAqB;YAK1B,kBAAkB;YAalB,iBAAiB;IAM/B;;;OAGG;IACU,eAAe,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAQtF"}
@@ -1 +0,0 @@
1
- {"version":3,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CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;SAC3F;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,SAAiB;QAC/C,MAAM,YAAY,GAAG,IAAI,sDAA4B,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACpG,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAC,WAA6B;QACxD,IAAI,OAAO,WAAW,KAAK,QAAQ;YACjC,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAE7C,OAAO,IAAA,oBAAK,EAAC,MAAM,oCAAY,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAA0B,EAAE,EAAE;YAC7G,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzCD,4CAyCC","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 Hierarchies\n */\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { Omit, RegisteredRuleset, Ruleset } from \"@itwin/presentation-common\";\nimport { PresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport { PRESENTATION_TREE_NODE_KEY } from \"@itwin/presentation-components/lib/presentation-components/tree/Utils\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeNodeItem } from \"@itwin/components-react\";\n\n/**\n * Structure that describes a Node with any indexed properties\n * except `children`.\n *\n * @public\n */\nexport interface MappedNode {\n /** Indexer for all properties in this data structure */\n [index: string]: any;\n /** Prohibited property */\n children?: never;\n}\n\n/**\n * Node in a hierarchy.\n * @public\n */\nexport interface HierarchyNode extends Omit<MappedNode, \"children\"> {\n /** Children of this node */\n children?: HierarchyNode[];\n}\n\n/**\n * A function that converts `TreeNodeItem` into a new custom object.\n * @public\n */\nexport type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;\n\n/**\n * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.\n * @public\n */\nexport const defaultNodeMappingFunc: NodeMappingFunc = (node: TreeNodeItem) => {\n // Skip properties 'id', 'parentId' as they contain internal stuff\n // that callers are most likely not interested in. Otherwise they can supply\n // a custom `NodeMappingFunc` that does return those properties as well.\n const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars\n return resultNode;\n};\n\n/**\n * Properties for creating a `HierarchyBuilder` instance.\n * @public\n */\nexport interface HierarchyBuilderProps {\n /** The iModel to pull data from */\n imodel: IModelConnection;\n /**\n * A function that maps node to something that the user of\n * this API is interested in. E.g. custom implementation may skip some unimportant\n * node properties to make resulting object smaller and easier to read.\n */\n nodeMappingFunc?: NodeMappingFunc;\n}\n\n/**\n * A class that constructs simple node hierarchy from specified\n * imodel and ruleset.\n *\n * @public\n */\nexport class HierarchyBuilder {\n private readonly _iModel: IModelConnection;\n private readonly _nodeMappingFunc: NodeMappingFunc;\n\n /** Constructor */\n constructor(props: HierarchyBuilderProps) {\n this._iModel = props.imodel;\n this._nodeMappingFunc = props.nodeMappingFunc ?? defaultNodeMappingFunc;\n }\n\n private async createSubHierarchy(nodes: TreeNodeItem[], dataProvider: PresentationTreeDataProvider) {\n const hierarchy: HierarchyNode[] = [];\n for (const node of nodes) {\n // istanbul ignore next: for some reason coverage tool thinks the below statement is conditional and one of branches is not covered...\n const { [PRESENTATION_TREE_NODE_KEY]: key, ...nodeNoKey } = (node as TreeNodeItem & { [PRESENTATION_TREE_NODE_KEY]: any }); // eslint-disable-line @typescript-eslint/no-unused-vars\n const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;\n const childNodes = await dataProvider.getNodes(node);\n if (childNodes.length > 0)\n hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);\n }\n return hierarchy;\n }\n\n private async doCreateHierarchy(rulesetId: string): Promise<HierarchyNode[]> {\n const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });\n const rootNodes = await dataProvider.getNodes();\n return this.createSubHierarchy(rootNodes, dataProvider);\n }\n\n /**\n * Create a hierarchy using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n */\n public async createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]> {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateHierarchy(rulesetOrId);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateHierarchy(ruleset.id);\n });\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"presentation-testing.d.ts","sourceRoot":"","sources":["../src/presentation-testing.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,cAAc,yCAAyC,CAAC;AAExD;;;;;GAKG;AACH,cAAc,uCAAuC,CAAC;AAEtD;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../src/presentation-testing.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C","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/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers\";\n"]}