@itwin/presentation-frontend 4.5.0-dev.2 → 4.5.0-dev.21

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 (116) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +1 -1
  4. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts.map +1 -1
  5. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +10 -6
  6. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  7. package/lib/cjs/presentation-frontend/Diagnostics.d.ts.map +1 -1
  8. package/lib/cjs/presentation-frontend/Diagnostics.js +18 -13
  9. package/lib/cjs/presentation-frontend/Diagnostics.js.map +1 -1
  10. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +3 -3
  11. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  12. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts.map +1 -1
  13. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +3 -3
  14. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  15. package/lib/cjs/presentation-frontend/LocalizationHelper.js +3 -3
  16. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  17. package/lib/cjs/presentation-frontend/Presentation.d.ts.map +1 -1
  18. package/lib/cjs/presentation-frontend/Presentation.js +26 -16
  19. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  20. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +7 -4
  21. package/lib/cjs/presentation-frontend/PresentationManager.d.ts.map +1 -1
  22. package/lib/cjs/presentation-frontend/PresentationManager.js +131 -96
  23. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  24. package/lib/cjs/presentation-frontend/RulesetManager.d.ts.map +1 -1
  25. package/lib/cjs/presentation-frontend/RulesetManager.js +11 -7
  26. package/lib/cjs/presentation-frontend/RulesetManager.js.map +1 -1
  27. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts.map +1 -1
  28. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +53 -31
  29. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  30. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +33 -4
  31. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  32. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +179 -74
  33. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  34. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts.map +1 -1
  35. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +54 -25
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  37. package/lib/cjs/presentation-frontend/selection/HiliteRules.json +172 -172
  38. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts.map +1 -1
  39. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +16 -10
  40. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  41. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +3 -3
  42. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  43. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts.map +1 -1
  44. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +3 -3
  45. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  46. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts.map +1 -1
  47. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +15 -9
  48. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  49. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  50. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +7 -5
  51. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  52. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
  53. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +31 -16
  54. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  55. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts.map +1 -1
  56. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +25 -14
  57. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  58. package/lib/cjs/presentation-frontend.js +3 -3
  59. package/lib/cjs/presentation-frontend.js.map +1 -1
  60. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts.map +1 -1
  61. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +10 -6
  62. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  63. package/lib/esm/presentation-frontend/Diagnostics.d.ts.map +1 -1
  64. package/lib/esm/presentation-frontend/Diagnostics.js +18 -13
  65. package/lib/esm/presentation-frontend/Diagnostics.js.map +1 -1
  66. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +3 -3
  67. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  68. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts.map +1 -1
  69. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +3 -3
  70. package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  71. package/lib/esm/presentation-frontend/LocalizationHelper.js +3 -3
  72. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  73. package/lib/esm/presentation-frontend/Presentation.d.ts.map +1 -1
  74. package/lib/esm/presentation-frontend/Presentation.js +26 -16
  75. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  76. package/lib/esm/presentation-frontend/PresentationManager.d.ts +7 -4
  77. package/lib/esm/presentation-frontend/PresentationManager.d.ts.map +1 -1
  78. package/lib/esm/presentation-frontend/PresentationManager.js +131 -96
  79. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  80. package/lib/esm/presentation-frontend/RulesetManager.d.ts.map +1 -1
  81. package/lib/esm/presentation-frontend/RulesetManager.js +11 -7
  82. package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
  83. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts.map +1 -1
  84. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +53 -31
  85. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  86. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +33 -4
  87. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  88. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +179 -74
  89. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  90. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts.map +1 -1
  91. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +54 -25
  92. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  93. package/lib/esm/presentation-frontend/selection/HiliteRules.json +172 -172
  94. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts.map +1 -1
  95. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +17 -11
  96. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  97. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +3 -3
  98. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  99. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts.map +1 -1
  100. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +3 -3
  101. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  102. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts.map +1 -1
  103. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +15 -9
  104. package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  105. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  106. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +7 -5
  107. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  108. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
  109. package/lib/esm/presentation-frontend/selection/SelectionManager.js +31 -16
  110. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  111. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts.map +1 -1
  112. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +25 -14
  113. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  114. package/lib/esm/presentation-frontend.js +3 -3
  115. package/lib/esm/presentation-frontend.js.map +1 -1
  116. package/package.json +19 -16
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  /** @packageDocumentation
7
7
  * @module Core
8
8
  */
@@ -33,7 +33,9 @@ class PresentationManager {
33
33
  get activeUnitSystem() {
34
34
  return this._explicitActiveUnitSystem ?? core_frontend_1.IModelApp.quantityFormatter.activeUnitSystem;
35
35
  }
36
- set activeUnitSystem(value) { this._explicitActiveUnitSystem = value; }
36
+ set activeUnitSystem(value) {
37
+ this._explicitActiveUnitSystem = value;
38
+ }
37
39
  constructor(props) {
38
40
  /**
39
41
  * An event raised when hierarchies created using specific ruleset change
@@ -54,11 +56,11 @@ class PresentationManager {
54
56
  // eslint-disable-next-line deprecation/deprecation
55
57
  this._explicitActiveUnitSystem = props.activeUnitSystem;
56
58
  }
57
- this._requestsHandler = props?.rpcRequestsHandler ?? new presentation_common_1.RpcRequestsHandler(props ? { clientId: props.clientId, timeout: props.requestTimeout } : undefined);
59
+ this._requestsHandler =
60
+ props?.rpcRequestsHandler ?? new presentation_common_1.RpcRequestsHandler(props ? { clientId: props.clientId, timeout: props.requestTimeout } : undefined);
58
61
  this._rulesetVars = new Map();
59
62
  this._rulesets = RulesetManager_1.RulesetManagerImpl.create();
60
63
  this._localizationHelper = new LocalizationHelper_1.FrontendLocalizationHelper(props?.activeLocale);
61
- this._connections = new Map();
62
64
  this._schemaContextProvider = props?.schemaContextProvider;
63
65
  this._defaultFormats = props?.defaultFormats;
64
66
  if (core_frontend_1.IpcApp.isValid) {
@@ -68,41 +70,38 @@ class PresentationManager {
68
70
  }
69
71
  }
70
72
  /** Get / set active locale used for localizing presentation data */
71
- get activeLocale() { return this._localizationHelper.locale; }
72
- set activeLocale(locale) { this._localizationHelper.locale = locale; }
73
+ get activeLocale() {
74
+ return this._localizationHelper.locale;
75
+ }
76
+ set activeLocale(locale) {
77
+ this._localizationHelper.locale = locale;
78
+ }
73
79
  dispose() {
74
80
  if (this._clearEventListener) {
75
81
  this._clearEventListener();
76
82
  this._clearEventListener = undefined;
77
83
  }
78
84
  }
79
- async onConnection(imodel) {
80
- if (!this._connections.has(imodel))
81
- this._connections.set(imodel, this.initializeIModel(imodel));
82
- await this._connections.get(imodel);
83
- }
84
- async initializeIModel(imodel) {
85
- imodel.onClose.addOnce(() => {
86
- this._connections.delete(imodel);
87
- });
88
- await this.onNewiModelConnection(imodel);
89
- }
90
85
  /** @note This is only called in native apps after changes in iModels */
91
86
  async handleUpdateAsync(report) {
92
87
  for (const imodelKey in report) {
93
88
  // istanbul ignore if
94
- if (!report.hasOwnProperty(imodelKey))
89
+ if (!report.hasOwnProperty(imodelKey)) {
95
90
  continue;
91
+ }
96
92
  const imodelReport = report[imodelKey];
97
93
  for (const rulesetId in imodelReport) {
98
94
  // istanbul ignore if
99
- if (!imodelReport.hasOwnProperty(rulesetId))
95
+ if (!imodelReport.hasOwnProperty(rulesetId)) {
100
96
  continue;
97
+ }
101
98
  const updateInfo = imodelReport[rulesetId];
102
- if (updateInfo.content)
99
+ if (updateInfo.content) {
103
100
  this.onIModelContentChanged.raiseEvent({ rulesetId, updateInfo: updateInfo.content, imodelKey });
104
- if (updateInfo.hierarchy)
101
+ }
102
+ if (updateInfo.hierarchy) {
105
103
  this.onIModelHierarchyChanged.raiseEvent({ rulesetId, updateInfo: updateInfo.hierarchy, imodelKey });
104
+ }
106
105
  }
107
106
  }
108
107
  }
@@ -110,7 +109,13 @@ class PresentationManager {
110
109
  * Function that is called when a new IModelConnection is used to retrieve data.
111
110
  * @internal
112
111
  */
113
- async onNewiModelConnection(_) { }
112
+ startIModelInitialization(_) { }
113
+ /**
114
+ * Function that should be called to finish initialization that was started at [[PresentationManager.startIModelInitialization]].
115
+ * Can be removed when [[FavoritePropertiesManager.has]] and [[FavoritePropertiesManager.sortFields]] are removed.
116
+ * @internal
117
+ */
118
+ async ensureIModelInitialized(_) { }
114
119
  /**
115
120
  * Create a new PresentationManager instance
116
121
  * @param props Optional properties used to configure the manager
@@ -119,13 +124,19 @@ class PresentationManager {
119
124
  return new PresentationManager(props);
120
125
  }
121
126
  /** @internal */
122
- get rpcRequestsHandler() { return this._requestsHandler; }
127
+ get rpcRequestsHandler() {
128
+ return this._requestsHandler;
129
+ }
123
130
  /** @internal */
124
- get ipcRequestsHandler() { return this._ipcRequestsHandler; }
131
+ get ipcRequestsHandler() {
132
+ return this._ipcRequestsHandler;
133
+ }
125
134
  /**
126
135
  * Get rulesets manager
127
136
  */
128
- rulesets() { return this._rulesets; }
137
+ rulesets() {
138
+ return this._rulesets;
139
+ }
129
140
  /**
130
141
  * Get ruleset variables manager for specific ruleset
131
142
  * @param rulesetId Id of the ruleset to get the vars manager for
@@ -142,8 +153,9 @@ class PresentationManager {
142
153
  // 2. put all `requestOptions` members (if `locale` or `unitSystem` are set, they'll override the defaults put at #1)
143
154
  // 3. put `imodel` of type `IModelRpcProps` which overwrites the `imodel` from `requestOptions` put at #2
144
155
  const defaultOptions = {};
145
- if (this.activeLocale)
156
+ if (this.activeLocale) {
146
157
  defaultOptions.locale = this.activeLocale;
158
+ }
147
159
  defaultOptions.unitSystem = this.activeUnitSystem; // eslint-disable-line deprecation/deprecation
148
160
  const { imodel, rulesetVariables, ...rpcRequestOptions } = requestOptions;
149
161
  return {
@@ -163,13 +175,14 @@ class PresentationManager {
163
175
  const foundRuleset = await this._rulesets.get(rulesetOrId);
164
176
  foundRulesetOrId = foundRuleset ? foundRuleset.toJSON() : rulesetOrId;
165
177
  }
166
- const rulesetId = (typeof foundRulesetOrId === "object") ? foundRulesetOrId.id : foundRulesetOrId;
178
+ const rulesetId = typeof foundRulesetOrId === "object" ? foundRulesetOrId.id : foundRulesetOrId;
167
179
  // All Id64Array variable values must be sorted for serialization to JSON to work. RulesetVariablesManager
168
180
  // sorts them before storing, so that part is taken care of, but we need to ensure that variables coming from
169
181
  // request options are also sorted.
170
182
  const variables = (rulesetVariables ?? []).map((variable) => {
171
- if (variable.type === presentation_common_1.VariableValueTypes.Id64Array)
183
+ if (variable.type === presentation_common_1.VariableValueTypes.Id64Array) {
172
184
  return { ...variable, value: core_bentley_1.OrderedId64Iterable.sortArray(variable.value) };
185
+ }
173
186
  return variable;
174
187
  });
175
188
  if (!this._ipcRequestsHandler) {
@@ -181,7 +194,7 @@ class PresentationManager {
181
194
  }
182
195
  /** Retrieves nodes */
183
196
  async getNodes(requestOptions) {
184
- await this.onConnection(requestOptions.imodel);
197
+ this.startIModelInitialization(requestOptions.imodel);
185
198
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
186
199
  const rpcOptions = this.toRpcTokenOptions({ ...options });
187
200
  const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions) => this._requestsHandler.getPagedNodes({ ...rpcOptions, paging: partialPageOptions }));
@@ -190,14 +203,14 @@ class PresentationManager {
190
203
  }
191
204
  /** Retrieves nodes count. */
192
205
  async getNodesCount(requestOptions) {
193
- await this.onConnection(requestOptions.imodel);
206
+ this.startIModelInitialization(requestOptions.imodel);
194
207
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
195
208
  const rpcOptions = this.toRpcTokenOptions({ ...options });
196
209
  return this._requestsHandler.getNodesCount(rpcOptions);
197
210
  }
198
211
  /** Retrieves total nodes count and a single page of nodes. */
199
212
  async getNodesAndCount(requestOptions) {
200
- await this.onConnection(requestOptions.imodel);
213
+ this.startIModelInitialization(requestOptions.imodel);
201
214
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
202
215
  const rpcOptions = this.toRpcTokenOptions({ ...options });
203
216
  const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions) => this._requestsHandler.getPagedNodes({ ...rpcOptions, paging: partialPageOptions }));
@@ -212,16 +225,21 @@ class PresentationManager {
212
225
  * @beta
213
226
  */
214
227
  async getNodesDescriptor(requestOptions) {
215
- await this.onConnection(requestOptions.imodel);
216
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
217
- const rpcOptions = this.toRpcTokenOptions({ ...options });
218
- const result = await this._requestsHandler.getNodesDescriptor(rpcOptions);
219
- const descriptor = presentation_common_1.Descriptor.fromJSON(result);
220
- return descriptor ? this._localizationHelper.getLocalizedContentDescriptor(descriptor) : undefined;
228
+ this.startIModelInitialization(requestOptions.imodel);
229
+ try {
230
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
231
+ const rpcOptions = this.toRpcTokenOptions({ ...options });
232
+ const result = await this._requestsHandler.getNodesDescriptor(rpcOptions);
233
+ const descriptor = presentation_common_1.Descriptor.fromJSON(result);
234
+ return descriptor ? this._localizationHelper.getLocalizedContentDescriptor(descriptor) : undefined;
235
+ }
236
+ finally {
237
+ await this.ensureIModelInitialized(requestOptions.imodel);
238
+ }
221
239
  }
222
240
  /** Retrieves paths from root nodes to children nodes according to specified keys. Intersecting paths will be merged. */
223
241
  async getNodePaths(requestOptions) {
224
- await this.onConnection(requestOptions.imodel);
242
+ this.startIModelInitialization(requestOptions.imodel);
225
243
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
226
244
  const rpcOptions = this.toRpcTokenOptions({ ...options });
227
245
  const result = await this._requestsHandler.getNodePaths(rpcOptions);
@@ -230,7 +248,7 @@ class PresentationManager {
230
248
  }
231
249
  /** Retrieves paths from root nodes to nodes containing filter text in their label. */
232
250
  async getFilteredNodePaths(requestOptions) {
233
- await this.onConnection(requestOptions.imodel);
251
+ this.startIModelInitialization(requestOptions.imodel);
234
252
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
235
253
  const result = await this._requestsHandler.getFilteredNodePaths(this.toRpcTokenOptions(options));
236
254
  // eslint-disable-next-line deprecation/deprecation
@@ -242,26 +260,31 @@ class PresentationManager {
242
260
  * @public
243
261
  */
244
262
  async getContentSources(requestOptions) {
245
- await this.onConnection(requestOptions.imodel);
263
+ this.startIModelInitialization(requestOptions.imodel);
246
264
  const rpcOptions = this.toRpcTokenOptions(requestOptions);
247
265
  const result = await this._requestsHandler.getContentSources(rpcOptions);
248
266
  return presentation_common_1.SelectClassInfo.listFromCompressedJSON(result.sources, result.classesMap);
249
267
  }
250
268
  /** Retrieves the content descriptor which describes the content and can be used to customize it. */
251
269
  async getContentDescriptor(requestOptions) {
252
- await this.onConnection(requestOptions.imodel);
253
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
254
- const rpcOptions = this.toRpcTokenOptions({
255
- ...options,
256
- keys: stripTransientElementKeys(options.keys).toJSON(),
257
- });
258
- const result = await this._requestsHandler.getContentDescriptor(rpcOptions);
259
- const descriptor = presentation_common_1.Descriptor.fromJSON(result);
260
- return descriptor ? this._localizationHelper.getLocalizedContentDescriptor(descriptor) : undefined;
270
+ this.startIModelInitialization(requestOptions.imodel);
271
+ try {
272
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
273
+ const rpcOptions = this.toRpcTokenOptions({
274
+ ...options,
275
+ keys: stripTransientElementKeys(options.keys).toJSON(),
276
+ });
277
+ const result = await this._requestsHandler.getContentDescriptor(rpcOptions);
278
+ const descriptor = presentation_common_1.Descriptor.fromJSON(result);
279
+ return descriptor ? this._localizationHelper.getLocalizedContentDescriptor(descriptor) : undefined;
280
+ }
281
+ finally {
282
+ await this.ensureIModelInitialized(requestOptions.imodel);
283
+ }
261
284
  }
262
285
  /** Retrieves overall content set size. */
263
286
  async getContentSetSize(requestOptions) {
264
- await this.onConnection(requestOptions.imodel);
287
+ this.startIModelInitialization(requestOptions.imodel);
265
288
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
266
289
  const rpcOptions = this.toRpcTokenOptions({
267
290
  ...options,
@@ -276,43 +299,49 @@ class PresentationManager {
276
299
  }
277
300
  /** Retrieves content set size and content which consists of a content descriptor and a page of records. */
278
301
  async getContentAndSize(requestOptions) {
279
- await this.onConnection(requestOptions.imodel);
280
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
281
- const rpcOptions = this.toRpcTokenOptions({
282
- ...options,
283
- descriptor: getDescriptorOverrides(requestOptions.descriptor),
284
- keys: stripTransientElementKeys(requestOptions.keys).toJSON(),
285
- ...(!requestOptions.omitFormattedValues && this._schemaContextProvider !== undefined ? { omitFormattedValues: true } : undefined),
286
- });
287
- let descriptor = (requestOptions.descriptor instanceof presentation_common_1.Descriptor) ? requestOptions.descriptor : undefined;
288
- const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions, requestIndex) => {
289
- if (0 === requestIndex && !descriptor) {
290
- const content = await this._requestsHandler.getPagedContent({ ...rpcOptions, paging: partialPageOptions });
291
- if (content) {
292
- descriptor = presentation_common_1.Descriptor.fromJSON(content.descriptor);
293
- return content.contentSet;
302
+ this.startIModelInitialization(requestOptions.imodel);
303
+ try {
304
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
305
+ const rpcOptions = this.toRpcTokenOptions({
306
+ ...options,
307
+ descriptor: getDescriptorOverrides(requestOptions.descriptor),
308
+ keys: stripTransientElementKeys(requestOptions.keys).toJSON(),
309
+ ...(!requestOptions.omitFormattedValues && this._schemaContextProvider !== undefined ? { omitFormattedValues: true } : undefined),
310
+ });
311
+ let descriptor = requestOptions.descriptor instanceof presentation_common_1.Descriptor ? requestOptions.descriptor : undefined;
312
+ const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions, requestIndex) => {
313
+ if (0 === requestIndex && !descriptor) {
314
+ const content = await this._requestsHandler.getPagedContent({ ...rpcOptions, paging: partialPageOptions });
315
+ if (content) {
316
+ descriptor = presentation_common_1.Descriptor.fromJSON(content.descriptor);
317
+ return content.contentSet;
318
+ }
319
+ return { total: 0, items: [] };
294
320
  }
295
- return { total: 0, items: [] };
321
+ return this._requestsHandler.getPagedContentSet({ ...rpcOptions, paging: partialPageOptions });
322
+ });
323
+ if (!descriptor) {
324
+ return undefined;
296
325
  }
297
- return this._requestsHandler.getPagedContentSet({ ...rpcOptions, paging: partialPageOptions });
298
- });
299
- if (!descriptor)
300
- return undefined;
301
- const items = result.items.map((itemJson) => presentation_common_1.Item.fromJSON(itemJson)).filter((item) => (item !== undefined));
302
- const resultContent = new presentation_common_1.Content(descriptor, items);
303
- if (!requestOptions.omitFormattedValues && this._schemaContextProvider) {
304
- const koqPropertyFormatter = new presentation_common_1.KoqPropertyValueFormatter(this._schemaContextProvider(requestOptions.imodel), this._defaultFormats);
305
- const contentFormatter = new presentation_common_1.ContentFormatter(new presentation_common_1.ContentPropertyValueFormatter(koqPropertyFormatter), requestOptions.unitSystem ?? this._explicitActiveUnitSystem ?? core_frontend_1.IModelApp.quantityFormatter.activeUnitSystem);
306
- await contentFormatter.formatContent(resultContent);
326
+ const items = result.items.map((itemJson) => presentation_common_1.Item.fromJSON(itemJson)).filter((item) => item !== undefined);
327
+ const resultContent = new presentation_common_1.Content(descriptor, items);
328
+ if (!requestOptions.omitFormattedValues && this._schemaContextProvider) {
329
+ const koqPropertyFormatter = new presentation_common_1.KoqPropertyValueFormatter(this._schemaContextProvider(requestOptions.imodel), this._defaultFormats);
330
+ const contentFormatter = new presentation_common_1.ContentFormatter(new presentation_common_1.ContentPropertyValueFormatter(koqPropertyFormatter), requestOptions.unitSystem ?? this._explicitActiveUnitSystem ?? core_frontend_1.IModelApp.quantityFormatter.activeUnitSystem);
331
+ await contentFormatter.formatContent(resultContent);
332
+ }
333
+ return {
334
+ size: result.total,
335
+ content: this._localizationHelper.getLocalizedContent(resultContent),
336
+ };
337
+ }
338
+ finally {
339
+ await this.ensureIModelInitialized(requestOptions.imodel);
307
340
  }
308
- return {
309
- size: result.total,
310
- content: this._localizationHelper.getLocalizedContent(resultContent),
311
- };
312
341
  }
313
342
  /** Retrieves distinct values of specific field from the content. */
314
343
  async getPagedDistinctValues(requestOptions) {
315
- await this.onConnection(requestOptions.imodel);
344
+ this.startIModelInitialization(requestOptions.imodel);
316
345
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
317
346
  const rpcOptions = {
318
347
  ...this.toRpcTokenOptions(options),
@@ -331,11 +360,12 @@ class PresentationManager {
331
360
  * @public
332
361
  */
333
362
  async getElementProperties(requestOptions) {
334
- await this.onConnection(requestOptions.imodel);
363
+ this.startIModelInitialization(requestOptions.imodel);
335
364
  const results = await this._requestsHandler.getElementProperties(this.toRpcTokenOptions(requestOptions));
336
365
  // istanbul ignore if
337
- if (!results)
366
+ if (!results) {
338
367
  return undefined;
368
+ }
339
369
  return this._localizationHelper.getLocalizedElementProperties(results);
340
370
  }
341
371
  /**
@@ -343,7 +373,7 @@ class PresentationManager {
343
373
  * @public
344
374
  */
345
375
  async getContentInstanceKeys(requestOptions) {
346
- await this.onConnection(requestOptions.imodel);
376
+ this.startIModelInitialization(requestOptions.imodel);
347
377
  const options = await this.addRulesetAndVariablesToOptions(requestOptions);
348
378
  const rpcOptions = {
349
379
  ...this.toRpcTokenOptions(options),
@@ -368,17 +398,17 @@ class PresentationManager {
368
398
  }
369
399
  /** Retrieves display label definition of specific item. */
370
400
  async getDisplayLabelDefinition(requestOptions) {
371
- await this.onConnection(requestOptions.imodel);
401
+ this.startIModelInitialization(requestOptions.imodel);
372
402
  const rpcOptions = this.toRpcTokenOptions({ ...requestOptions });
373
403
  const result = await this._requestsHandler.getDisplayLabelDefinition(rpcOptions);
374
404
  return this._localizationHelper.getLocalizedLabelDefinition(result);
375
405
  }
376
406
  /** Retrieves display label definition of specific items. */
377
407
  async getDisplayLabelDefinitions(requestOptions) {
378
- await this.onConnection(requestOptions.imodel);
408
+ this.startIModelInitialization(requestOptions.imodel);
379
409
  const rpcOptions = this.toRpcTokenOptions({ ...requestOptions });
380
410
  const result = await (0, exports.buildPagedArrayResponse)(undefined, async (partialPageOptions) => {
381
- const partialKeys = (!partialPageOptions.start) ? rpcOptions.keys : rpcOptions.keys.slice(partialPageOptions.start);
411
+ const partialKeys = !partialPageOptions.start ? rpcOptions.keys : rpcOptions.keys.slice(partialPageOptions.start);
382
412
  return this._requestsHandler.getPagedDisplayLabelDefinitions({ ...rpcOptions, keys: partialKeys });
383
413
  });
384
414
  return this._localizationHelper.getLocalizedLabelDefinitions(result.items);
@@ -386,8 +416,9 @@ class PresentationManager {
386
416
  }
387
417
  exports.PresentationManager = PresentationManager;
388
418
  const getDescriptorOverrides = (descriptorOrOverrides) => {
389
- if (descriptorOrOverrides instanceof presentation_common_1.Descriptor)
419
+ if (descriptorOrOverrides instanceof presentation_common_1.Descriptor) {
390
420
  return descriptorOrOverrides.createDescriptorOverrides();
421
+ }
391
422
  return descriptorOrOverrides;
392
423
  };
393
424
  async function createPagedGeneratorResponse(props) {
@@ -405,14 +436,17 @@ async function createPagedGeneratorResponse(props) {
405
436
  }
406
437
  const receivedItemsCount = partialResult.items.length;
407
438
  if (partialResult.total !== 0 && receivedItemsCount === 0) {
408
- if (pageStart >= partialResult.total)
439
+ if (pageStart >= partialResult.total) {
409
440
  throw new Error(`Requested page with start index ${pageStart} is out of bounds. Total number of items: ${partialResult.total}`);
441
+ }
410
442
  throw new Error("Paged request returned non zero total count but no items");
411
443
  }
412
- if (pageSize !== 0 && receivedItemsCount >= pageSize || receivedItemsCount >= (partialResult.total - pageStart))
444
+ if ((pageSize !== 0 && receivedItemsCount >= pageSize) || receivedItemsCount >= partialResult.total - pageStart) {
413
445
  break;
414
- if (pageSize !== 0)
446
+ }
447
+ if (pageSize !== 0) {
415
448
  pageSize -= receivedItemsCount;
449
+ }
416
450
  pageStart += receivedItemsCount;
417
451
  partialResult = await props.get({ start: pageStart, size: pageSize }, requestIndex++);
418
452
  }
@@ -430,15 +464,16 @@ const buildPagedArrayResponse = async (requestedPage, getter) => {
430
464
  };
431
465
  exports.buildPagedArrayResponse = buildPagedArrayResponse;
432
466
  const stripTransientElementKeys = (keys) => {
433
- if (!keys.some((key) => presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME))
467
+ if (!keys.some((key) => presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME)) {
434
468
  return keys;
469
+ }
435
470
  const copy = new presentation_common_1.KeySet();
436
471
  copy.add(keys, (key) => {
437
472
  // the callback is not going to be called with EntityProps as KeySet converts them
438
473
  // to InstanceKeys, but we want to keep the EntityProps case for correctness
439
474
  // istanbul ignore next
440
- const isTransient = presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME
441
- || presentation_common_1.Key.isEntityProps(key) && key.classFullName === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME;
475
+ const isTransient = (presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME) ||
476
+ (presentation_common_1.Key.isEntityProps(key) && key.classFullName === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME);
442
477
  return !isTransient;
443
478
  });
444
479
  return copy;