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