@itwin/presentation-frontend 4.0.0-dev.52 → 4.0.0-dev.55

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 (88) hide show
  1. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  2. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +47 -47
  3. package/lib/cjs/presentation-frontend/Diagnostics.d.ts +14 -14
  4. package/lib/cjs/presentation-frontend/Diagnostics.js +61 -61
  5. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  6. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +20 -20
  7. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  8. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +41 -41
  9. package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts +10 -10
  10. package/lib/cjs/presentation-frontend/LocalizationHelper.js +31 -31
  11. package/lib/cjs/presentation-frontend/Presentation.d.ts +73 -73
  12. package/lib/cjs/presentation-frontend/Presentation.js +159 -159
  13. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +205 -205
  14. package/lib/cjs/presentation-frontend/PresentationManager.js +438 -438
  15. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  16. package/lib/cjs/presentation-frontend/RulesetManager.d.ts +63 -63
  17. package/lib/cjs/presentation-frontend/RulesetManager.js +85 -85
  18. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  19. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +195 -195
  20. package/lib/cjs/presentation-frontend/StateTracker.d.ts +38 -38
  21. package/lib/cjs/presentation-frontend/StateTracker.js +128 -128
  22. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  23. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  24. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +519 -519
  25. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  26. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  27. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +290 -290
  28. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  29. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +97 -97
  30. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  31. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +9 -9
  32. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  33. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +33 -33
  34. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  35. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +108 -108
  36. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts +17 -17
  37. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +40 -40
  38. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  39. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +414 -414
  40. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  41. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +91 -91
  42. package/lib/cjs/presentation-frontend.d.ts +34 -34
  43. package/lib/cjs/presentation-frontend.js +54 -50
  44. package/lib/cjs/presentation-frontend.js.map +1 -1
  45. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  46. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +43 -43
  47. package/lib/esm/presentation-frontend/Diagnostics.d.ts +14 -14
  48. package/lib/esm/presentation-frontend/Diagnostics.js +56 -56
  49. package/lib/esm/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  50. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +17 -17
  51. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  52. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +37 -37
  53. package/lib/esm/presentation-frontend/LocalizationHelper.d.ts +10 -10
  54. package/lib/esm/presentation-frontend/LocalizationHelper.js +27 -27
  55. package/lib/esm/presentation-frontend/Presentation.d.ts +73 -73
  56. package/lib/esm/presentation-frontend/Presentation.js +155 -155
  57. package/lib/esm/presentation-frontend/PresentationManager.d.ts +205 -205
  58. package/lib/esm/presentation-frontend/PresentationManager.js +433 -433
  59. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  60. package/lib/esm/presentation-frontend/RulesetManager.d.ts +63 -63
  61. package/lib/esm/presentation-frontend/RulesetManager.js +81 -81
  62. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  63. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +191 -191
  64. package/lib/esm/presentation-frontend/StateTracker.d.ts +38 -38
  65. package/lib/esm/presentation-frontend/StateTracker.js +124 -124
  66. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  67. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  68. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +514 -513
  69. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  70. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  71. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +282 -282
  72. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  73. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +93 -93
  74. package/lib/esm/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  75. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +8 -8
  76. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  77. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +29 -29
  78. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  79. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +104 -104
  80. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts +17 -17
  81. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +36 -36
  82. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  83. package/lib/esm/presentation-frontend/selection/SelectionManager.js +409 -409
  84. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  85. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +85 -85
  86. package/lib/esm/presentation-frontend.d.ts +34 -34
  87. package/lib/esm/presentation-frontend.js +38 -38
  88. package/package.json +15 -15
@@ -1,439 +1,439 @@
1
- "use strict";
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
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Core
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.buildPagedArrayResponse = exports.PresentationManager = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_frontend_1 = require("@itwin/core-frontend");
13
- const presentation_common_1 = require("@itwin/presentation-common");
14
- const IpcRequestsHandler_1 = require("./IpcRequestsHandler");
15
- const LocalizationHelper_1 = require("./LocalizationHelper");
16
- const RulesetManager_1 = require("./RulesetManager");
17
- const RulesetVariablesManager_1 = require("./RulesetVariablesManager");
18
- const SelectionManager_1 = require("./selection/SelectionManager");
19
- const StateTracker_1 = require("./StateTracker");
20
- /**
21
- * Frontend Presentation manager which basically just forwards all calls to
22
- * the backend implementation.
23
- *
24
- * @public
25
- */
26
- class PresentationManager {
27
- constructor(props) {
28
- /**
29
- * An event raised when hierarchies created using specific ruleset change
30
- * @alpha
31
- */
32
- this.onIModelHierarchyChanged = new core_bentley_1.BeEvent();
33
- /**
34
- * An event raised when content created using specific ruleset changes
35
- * @alpha
36
- */
37
- this.onIModelContentChanged = new core_bentley_1.BeEvent();
38
- // eslint-disable-next-line @typescript-eslint/naming-convention
39
- this.onUpdate = (_evt, report) => {
40
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
41
- this.handleUpdateAsync(presentation_common_1.UpdateInfo.fromJSON(report));
42
- };
43
- if (props) {
44
- // eslint-disable-next-line deprecation/deprecation
45
- this._explicitActiveUnitSystem = props.activeUnitSystem;
46
- }
47
- this._requestsHandler = props?.rpcRequestsHandler ?? new presentation_common_1.RpcRequestsHandler(props ? { clientId: props.clientId, timeout: props.requestTimeout } : undefined);
48
- this._rulesetVars = new Map();
49
- this._rulesets = RulesetManager_1.RulesetManagerImpl.create();
50
- this._localizationHelper = new LocalizationHelper_1.FrontendLocalizationHelper(props?.activeLocale);
51
- this._connections = new Map();
52
- if (core_frontend_1.IpcApp.isValid) {
53
- // Ipc only works in ipc apps, so the `onUpdate` callback will only be called there.
54
- this._clearEventListener = core_frontend_1.IpcApp.addListener(presentation_common_1.PresentationIpcEvents.Update, this.onUpdate);
55
- this._ipcRequestsHandler = props?.ipcRequestsHandler ?? new IpcRequestsHandler_1.IpcRequestsHandler(this._requestsHandler.clientId);
56
- this._stateTracker = props?.stateTracker ?? new StateTracker_1.StateTracker(this._ipcRequestsHandler);
57
- }
58
- }
59
- /**
60
- * Get / set active unit system used to format property values with units.
61
- *
62
- * @deprecated in 4.0. `IModelApp.quantityFormatter` should be used to get/set the active unit system. At the moment
63
- * [[PresentationManager]] allows overriding it, but returns `IModelApp.quantityFormatter.activeUnitSystem` if override
64
- * is not set.
65
- */
66
- get activeUnitSystem() {
67
- return this._explicitActiveUnitSystem ?? core_frontend_1.IModelApp.quantityFormatter.activeUnitSystem;
68
- }
69
- set activeUnitSystem(value) { this._explicitActiveUnitSystem = value; }
70
- /** 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
- dispose() {
74
- if (this._clearEventListener) {
75
- this._clearEventListener();
76
- this._clearEventListener = undefined;
77
- }
78
- }
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
- /** @note This is only called in native apps after changes in iModels */
91
- async handleUpdateAsync(report) {
92
- for (const imodelKey in report) {
93
- // istanbul ignore if
94
- if (!report.hasOwnProperty(imodelKey))
95
- continue;
96
- const imodelReport = report[imodelKey];
97
- for (const rulesetId in imodelReport) {
98
- // istanbul ignore if
99
- if (!imodelReport.hasOwnProperty(rulesetId))
100
- continue;
101
- const updateInfo = imodelReport[rulesetId];
102
- if (updateInfo.content)
103
- this.onIModelContentChanged.raiseEvent({ rulesetId, updateInfo: updateInfo.content, imodelKey });
104
- if (updateInfo.hierarchy)
105
- this.onIModelHierarchyChanged.raiseEvent({ rulesetId, updateInfo: updateInfo.hierarchy, imodelKey });
106
- }
107
- }
108
- }
109
- /**
110
- * Function that is called when a new IModelConnection is used to retrieve data.
111
- * @internal
112
- */
113
- async onNewiModelConnection(_) { }
114
- /**
115
- * Create a new PresentationManager instance
116
- * @param props Optional properties used to configure the manager
117
- */
118
- static create(props) {
119
- return new PresentationManager(props);
120
- }
121
- /** @internal */
122
- get rpcRequestsHandler() { return this._requestsHandler; }
123
- /** @internal */
124
- get ipcRequestsHandler() { return this._ipcRequestsHandler; }
125
- /** @internal */
126
- get stateTracker() { return this._stateTracker; }
127
- /**
128
- * Get rulesets manager
129
- */
130
- rulesets() { return this._rulesets; }
131
- /**
132
- * Get ruleset variables manager for specific ruleset
133
- * @param rulesetId Id of the ruleset to get the vars manager for
134
- */
135
- vars(rulesetId) {
136
- if (!this._rulesetVars.has(rulesetId)) {
137
- const varsManager = new RulesetVariablesManager_1.RulesetVariablesManagerImpl(rulesetId, this._ipcRequestsHandler);
138
- this._rulesetVars.set(rulesetId, varsManager);
139
- }
140
- return this._rulesetVars.get(rulesetId);
141
- }
142
- toRpcTokenOptions(requestOptions) {
143
- // 1. put default `locale` and `unitSystem`
144
- // 2. put all `requestOptions` members (if `locale` or `unitSystem` are set, they'll override the defaults put at #1)
145
- // 3. put `imodel` of type `IModelRpcProps` which overwrites the `imodel` from `requestOptions` put at #2
146
- const defaultOptions = {};
147
- if (this.activeLocale)
148
- defaultOptions.locale = this.activeLocale;
149
- defaultOptions.unitSystem = this.activeUnitSystem; // eslint-disable-line deprecation/deprecation
150
- const { imodel, rulesetVariables, ...rpcRequestOptions } = requestOptions;
151
- return {
152
- ...defaultOptions,
153
- ...rpcRequestOptions,
154
- ...(rulesetVariables ? { rulesetVariables: rulesetVariables.map(presentation_common_1.RulesetVariable.toJSON) } : {}),
155
- imodel: imodel.getRpcProps(),
156
- };
157
- }
158
- async addRulesetAndVariablesToOptions(options) {
159
- const { rulesetOrId, rulesetVariables } = options;
160
- let foundRulesetOrId;
161
- if (typeof rulesetOrId === "object") {
162
- foundRulesetOrId = rulesetOrId;
163
- }
164
- else {
165
- const foundRuleset = await this._rulesets.get(rulesetOrId);
166
- foundRulesetOrId = foundRuleset ? foundRuleset.toJSON() : rulesetOrId;
167
- }
168
- const rulesetId = (typeof foundRulesetOrId === "object") ? foundRulesetOrId.id : foundRulesetOrId;
169
- // All Id64Array variable values must be sorted for serialization to JSON to work. RulesetVariablesManager
170
- // sorts them before storing, so that part is taken care of, but we need to ensure that variables coming from
171
- // request options are also sorted.
172
- const variables = (rulesetVariables ?? []).map((variable) => {
173
- if (variable.type === presentation_common_1.VariableValueTypes.Id64Array)
174
- return { ...variable, value: core_bentley_1.OrderedId64Iterable.sortArray(variable.value) };
175
- return variable;
176
- });
177
- if (!this._ipcRequestsHandler) {
178
- // only need to add variables from variables manager if there's no IPC
179
- // handler - if there is one, the variables are already known by the backend
180
- variables.push(...this.vars(rulesetId).getAllVariables());
181
- }
182
- return { ...options, rulesetOrId: foundRulesetOrId, rulesetVariables: variables };
183
- }
184
- /** Retrieves nodes */
185
- async getNodes(requestOptions) {
186
- await this.onConnection(requestOptions.imodel);
187
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
188
- const rpcOptions = this.toRpcTokenOptions({ ...options });
189
- const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions) => this._requestsHandler.getPagedNodes({ ...rpcOptions, paging: partialPageOptions }));
190
- // eslint-disable-next-line deprecation/deprecation
191
- return this._localizationHelper.getLocalizedNodes(result.items.map(presentation_common_1.Node.fromJSON));
192
- }
193
- /** Retrieves nodes count. */
194
- async getNodesCount(requestOptions) {
195
- await this.onConnection(requestOptions.imodel);
196
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
197
- const rpcOptions = this.toRpcTokenOptions({ ...options });
198
- return this._requestsHandler.getNodesCount(rpcOptions);
199
- }
200
- /** Retrieves total nodes count and a single page of nodes. */
201
- async getNodesAndCount(requestOptions) {
202
- await this.onConnection(requestOptions.imodel);
203
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
204
- const rpcOptions = this.toRpcTokenOptions({ ...options });
205
- const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions) => this._requestsHandler.getPagedNodes({ ...rpcOptions, paging: partialPageOptions }));
206
- return {
207
- count: result.total,
208
- // eslint-disable-next-line deprecation/deprecation
209
- nodes: this._localizationHelper.getLocalizedNodes(result.items.map(presentation_common_1.Node.fromJSON)),
210
- };
211
- }
212
- /**
213
- * Retrieves hierarchy level descriptor.
214
- * @beta
215
- */
216
- async getNodesDescriptor(requestOptions) {
217
- await this.onConnection(requestOptions.imodel);
218
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
219
- const rpcOptions = this.toRpcTokenOptions({ ...options });
220
- const result = await this._requestsHandler.getNodesDescriptor(rpcOptions);
221
- return presentation_common_1.Descriptor.fromJSON(result);
222
- }
223
- /** Retrieves paths from root nodes to children nodes according to specified keys. Intersecting paths will be merged. */
224
- async getNodePaths(requestOptions) {
225
- await this.onConnection(requestOptions.imodel);
226
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
227
- const rpcOptions = this.toRpcTokenOptions({ ...options });
228
- const result = await this._requestsHandler.getNodePaths(rpcOptions);
229
- // eslint-disable-next-line deprecation/deprecation
230
- return result.map(presentation_common_1.NodePathElement.fromJSON);
231
- }
232
- /** Retrieves paths from root nodes to nodes containing filter text in their label. */
233
- async getFilteredNodePaths(requestOptions) {
234
- await this.onConnection(requestOptions.imodel);
235
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
236
- const result = await this._requestsHandler.getFilteredNodePaths(this.toRpcTokenOptions(options));
237
- // eslint-disable-next-line deprecation/deprecation
238
- return result.map(presentation_common_1.NodePathElement.fromJSON);
239
- }
240
- /**
241
- * Get information about the sources of content when building it for specific ECClasses. Sources involve classes of the primary select instance,
242
- * its related instances for loading related and navigation properties.
243
- * @public
244
- */
245
- async getContentSources(requestOptions) {
246
- await this.onConnection(requestOptions.imodel);
247
- const rpcOptions = this.toRpcTokenOptions(requestOptions);
248
- const result = await this._requestsHandler.getContentSources(rpcOptions);
249
- return presentation_common_1.SelectClassInfo.listFromCompressedJSON(result.sources, result.classesMap);
250
- }
251
- /** Retrieves the content descriptor which describes the content and can be used to customize it. */
252
- async getContentDescriptor(requestOptions) {
253
- await this.onConnection(requestOptions.imodel);
254
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
255
- const rpcOptions = this.toRpcTokenOptions({
256
- ...options,
257
- keys: stripTransientElementKeys(options.keys).toJSON(),
258
- });
259
- const result = await this._requestsHandler.getContentDescriptor(rpcOptions);
260
- return presentation_common_1.Descriptor.fromJSON(result);
261
- }
262
- /** Retrieves overall content set size. */
263
- async getContentSetSize(requestOptions) {
264
- await this.onConnection(requestOptions.imodel);
265
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
266
- const rpcOptions = this.toRpcTokenOptions({
267
- ...options,
268
- descriptor: getDescriptorOverrides(requestOptions.descriptor),
269
- keys: stripTransientElementKeys(requestOptions.keys).toJSON(),
270
- });
271
- return this._requestsHandler.getContentSetSize(rpcOptions);
272
- }
273
- /** Retrieves content which consists of a content descriptor and a page of records. */
274
- async getContent(requestOptions) {
275
- return (await this.getContentAndSize(requestOptions))?.content;
276
- }
277
- /** Retrieves content set size and content which consists of a content descriptor and a page of records. */
278
- 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
- });
286
- let descriptor = (requestOptions.descriptor instanceof presentation_common_1.Descriptor) ? requestOptions.descriptor : undefined;
287
- const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions, requestIndex) => {
288
- if (0 === requestIndex && !descriptor) {
289
- const content = await this._requestsHandler.getPagedContent({ ...rpcOptions, paging: partialPageOptions });
290
- if (content) {
291
- descriptor = presentation_common_1.Descriptor.fromJSON(content.descriptor);
292
- return content.contentSet;
293
- }
294
- return { total: 0, items: [] };
295
- }
296
- return this._requestsHandler.getPagedContentSet({ ...rpcOptions, paging: partialPageOptions });
297
- });
298
- if (!descriptor)
299
- return undefined;
300
- const items = result.items.map((itemJson) => presentation_common_1.Item.fromJSON(itemJson)).filter((item) => (item !== undefined));
301
- return {
302
- size: result.total,
303
- content: this._localizationHelper.getLocalizedContent(new presentation_common_1.Content(descriptor, items)),
304
- };
305
- }
306
- /** Retrieves distinct values of specific field from the content. */
307
- async getPagedDistinctValues(requestOptions) {
308
- await this.onConnection(requestOptions.imodel);
309
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
310
- const rpcOptions = {
311
- ...this.toRpcTokenOptions(options),
312
- descriptor: getDescriptorOverrides(options.descriptor),
313
- keys: stripTransientElementKeys(options.keys).toJSON(),
314
- };
315
- const result = await (0, exports.buildPagedArrayResponse)(requestOptions.paging, async (partialPageOptions) => this._requestsHandler.getPagedDistinctValues({ ...rpcOptions, paging: partialPageOptions }));
316
- return {
317
- ...result,
318
- // eslint-disable-next-line deprecation/deprecation
319
- items: result.items.map(presentation_common_1.DisplayValueGroup.fromJSON),
320
- };
321
- }
322
- /**
323
- * Retrieves property data in a simplified format for a single element specified by ID.
324
- * @public
325
- */
326
- async getElementProperties(requestOptions) {
327
- await this.onConnection(requestOptions.imodel);
328
- const results = await this._requestsHandler.getElementProperties(this.toRpcTokenOptions(requestOptions));
329
- // istanbul ignore if
330
- if (!results)
331
- return undefined;
332
- return this._localizationHelper.getLocalizedElementProperties(results);
333
- }
334
- /**
335
- * Retrieves content item instance keys.
336
- * @public
337
- */
338
- async getContentInstanceKeys(requestOptions) {
339
- await this.onConnection(requestOptions.imodel);
340
- const options = await this.addRulesetAndVariablesToOptions(requestOptions);
341
- const rpcOptions = {
342
- ...this.toRpcTokenOptions(options),
343
- keys: stripTransientElementKeys(options.keys).toJSON(),
344
- };
345
- const props = {
346
- page: requestOptions.paging,
347
- get: async (page) => {
348
- const keys = await this._requestsHandler.getContentInstanceKeys({ ...rpcOptions, paging: page });
349
- return {
350
- total: keys.total,
351
- items: keys.items.instanceKeys.reduce((instanceKeys, entry) => {
352
- for (const id of core_bentley_1.CompressedId64Set.iterable(entry[1])) {
353
- instanceKeys.push({ className: entry[0], id });
354
- }
355
- return instanceKeys;
356
- }, new Array()),
357
- };
358
- },
359
- };
360
- return createPagedGeneratorResponse(props);
361
- }
362
- /** Retrieves display label definition of specific item. */
363
- async getDisplayLabelDefinition(requestOptions) {
364
- await this.onConnection(requestOptions.imodel);
365
- const rpcOptions = this.toRpcTokenOptions({ ...requestOptions });
366
- const result = await this._requestsHandler.getDisplayLabelDefinition(rpcOptions);
367
- return this._localizationHelper.getLocalizedLabelDefinition(result);
368
- }
369
- /** Retrieves display label definition of specific items. */
370
- async getDisplayLabelDefinitions(requestOptions) {
371
- await this.onConnection(requestOptions.imodel);
372
- const rpcOptions = this.toRpcTokenOptions({ ...requestOptions });
373
- const result = await (0, exports.buildPagedArrayResponse)(undefined, async (partialPageOptions) => {
374
- const partialKeys = (!partialPageOptions.start) ? rpcOptions.keys : rpcOptions.keys.slice(partialPageOptions.start);
375
- return this._requestsHandler.getPagedDisplayLabelDefinitions({ ...rpcOptions, keys: partialKeys });
376
- });
377
- return this._localizationHelper.getLocalizedLabelDefinitions(result.items);
378
- }
379
- }
380
- exports.PresentationManager = PresentationManager;
381
- const getDescriptorOverrides = (descriptorOrOverrides) => {
382
- if (descriptorOrOverrides instanceof presentation_common_1.Descriptor)
383
- return descriptorOrOverrides.createDescriptorOverrides();
384
- return descriptorOrOverrides;
385
- };
386
- async function createPagedGeneratorResponse(props) {
387
- let pageStart = props.page?.start ?? 0;
388
- let pageSize = props.page?.size ?? 0;
389
- let requestIndex = 0;
390
- const firstPage = await props.get({ start: pageStart, size: pageSize }, requestIndex++);
391
- return {
392
- total: firstPage.total,
393
- async *items() {
394
- let partialResult = firstPage;
395
- while (true) {
396
- for (const item of partialResult.items) {
397
- yield item;
398
- }
399
- const receivedItemsCount = partialResult.items.length;
400
- if (partialResult.total !== 0 && receivedItemsCount === 0) {
401
- if (pageStart >= partialResult.total)
402
- throw new Error(`Requested page with start index ${pageStart} is out of bounds. Total number of items: ${partialResult.total}`);
403
- throw new Error("Paged request returned non zero total count but no items");
404
- }
405
- if (pageSize !== 0 && receivedItemsCount >= pageSize || receivedItemsCount >= (partialResult.total - pageStart))
406
- break;
407
- if (pageSize !== 0)
408
- pageSize -= receivedItemsCount;
409
- pageStart += receivedItemsCount;
410
- partialResult = await props.get({ start: pageStart, size: pageSize }, requestIndex++);
411
- }
412
- },
413
- };
414
- }
415
- /** @internal */
416
- const buildPagedArrayResponse = async (requestedPage, getter) => {
417
- const items = new Array();
418
- const gen = await createPagedGeneratorResponse({ page: requestedPage, get: getter });
419
- for await (const item of gen.items()) {
420
- items.push(item);
421
- }
422
- return { total: gen.total, items };
423
- };
424
- exports.buildPagedArrayResponse = buildPagedArrayResponse;
425
- const stripTransientElementKeys = (keys) => {
426
- if (!keys.some((key) => presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME))
427
- return keys;
428
- const copy = new presentation_common_1.KeySet();
429
- copy.add(keys, (key) => {
430
- // the callback is not going to be called with EntityProps as KeySet converts them
431
- // to InstanceKeys, but we want to keep the EntityProps case for correctness
432
- // istanbul ignore next
433
- const isTransient = presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME
434
- || presentation_common_1.Key.isEntityProps(key) && key.classFullName === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME;
435
- return !isTransient;
436
- });
437
- return copy;
438
- };
1
+ "use strict";
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
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Core
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.buildPagedArrayResponse = exports.PresentationManager = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_frontend_1 = require("@itwin/core-frontend");
13
+ const presentation_common_1 = require("@itwin/presentation-common");
14
+ const IpcRequestsHandler_1 = require("./IpcRequestsHandler");
15
+ const LocalizationHelper_1 = require("./LocalizationHelper");
16
+ const RulesetManager_1 = require("./RulesetManager");
17
+ const RulesetVariablesManager_1 = require("./RulesetVariablesManager");
18
+ const SelectionManager_1 = require("./selection/SelectionManager");
19
+ const StateTracker_1 = require("./StateTracker");
20
+ /**
21
+ * Frontend Presentation manager which basically just forwards all calls to
22
+ * the backend implementation.
23
+ *
24
+ * @public
25
+ */
26
+ class PresentationManager {
27
+ /**
28
+ * Get / set active unit system used to format property values with units.
29
+ *
30
+ * @deprecated in 4.0. `IModelApp.quantityFormatter` should be used to get/set the active unit system. At the moment
31
+ * [[PresentationManager]] allows overriding it, but returns `IModelApp.quantityFormatter.activeUnitSystem` if override
32
+ * is not set.
33
+ */
34
+ get activeUnitSystem() {
35
+ return this._explicitActiveUnitSystem ?? core_frontend_1.IModelApp.quantityFormatter.activeUnitSystem;
36
+ }
37
+ set activeUnitSystem(value) { this._explicitActiveUnitSystem = value; }
38
+ constructor(props) {
39
+ /**
40
+ * An event raised when hierarchies created using specific ruleset change
41
+ * @alpha
42
+ */
43
+ this.onIModelHierarchyChanged = new core_bentley_1.BeEvent();
44
+ /**
45
+ * An event raised when content created using specific ruleset changes
46
+ * @alpha
47
+ */
48
+ this.onIModelContentChanged = new core_bentley_1.BeEvent();
49
+ // eslint-disable-next-line @typescript-eslint/naming-convention
50
+ this.onUpdate = (_evt, report) => {
51
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
52
+ this.handleUpdateAsync(presentation_common_1.UpdateInfo.fromJSON(report));
53
+ };
54
+ if (props) {
55
+ // eslint-disable-next-line deprecation/deprecation
56
+ this._explicitActiveUnitSystem = props.activeUnitSystem;
57
+ }
58
+ this._requestsHandler = props?.rpcRequestsHandler ?? new presentation_common_1.RpcRequestsHandler(props ? { clientId: props.clientId, timeout: props.requestTimeout } : undefined);
59
+ this._rulesetVars = new Map();
60
+ this._rulesets = RulesetManager_1.RulesetManagerImpl.create();
61
+ this._localizationHelper = new LocalizationHelper_1.FrontendLocalizationHelper(props?.activeLocale);
62
+ this._connections = new Map();
63
+ if (core_frontend_1.IpcApp.isValid) {
64
+ // Ipc only works in ipc apps, so the `onUpdate` callback will only be called there.
65
+ this._clearEventListener = core_frontend_1.IpcApp.addListener(presentation_common_1.PresentationIpcEvents.Update, this.onUpdate);
66
+ this._ipcRequestsHandler = props?.ipcRequestsHandler ?? new IpcRequestsHandler_1.IpcRequestsHandler(this._requestsHandler.clientId);
67
+ this._stateTracker = props?.stateTracker ?? new StateTracker_1.StateTracker(this._ipcRequestsHandler);
68
+ }
69
+ }
70
+ /** 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
+ dispose() {
74
+ if (this._clearEventListener) {
75
+ this._clearEventListener();
76
+ this._clearEventListener = undefined;
77
+ }
78
+ }
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
+ /** @note This is only called in native apps after changes in iModels */
91
+ async handleUpdateAsync(report) {
92
+ for (const imodelKey in report) {
93
+ // istanbul ignore if
94
+ if (!report.hasOwnProperty(imodelKey))
95
+ continue;
96
+ const imodelReport = report[imodelKey];
97
+ for (const rulesetId in imodelReport) {
98
+ // istanbul ignore if
99
+ if (!imodelReport.hasOwnProperty(rulesetId))
100
+ continue;
101
+ const updateInfo = imodelReport[rulesetId];
102
+ if (updateInfo.content)
103
+ this.onIModelContentChanged.raiseEvent({ rulesetId, updateInfo: updateInfo.content, imodelKey });
104
+ if (updateInfo.hierarchy)
105
+ this.onIModelHierarchyChanged.raiseEvent({ rulesetId, updateInfo: updateInfo.hierarchy, imodelKey });
106
+ }
107
+ }
108
+ }
109
+ /**
110
+ * Function that is called when a new IModelConnection is used to retrieve data.
111
+ * @internal
112
+ */
113
+ async onNewiModelConnection(_) { }
114
+ /**
115
+ * Create a new PresentationManager instance
116
+ * @param props Optional properties used to configure the manager
117
+ */
118
+ static create(props) {
119
+ return new PresentationManager(props);
120
+ }
121
+ /** @internal */
122
+ get rpcRequestsHandler() { return this._requestsHandler; }
123
+ /** @internal */
124
+ get ipcRequestsHandler() { return this._ipcRequestsHandler; }
125
+ /** @internal */
126
+ get stateTracker() { return this._stateTracker; }
127
+ /**
128
+ * Get rulesets manager
129
+ */
130
+ rulesets() { return this._rulesets; }
131
+ /**
132
+ * Get ruleset variables manager for specific ruleset
133
+ * @param rulesetId Id of the ruleset to get the vars manager for
134
+ */
135
+ vars(rulesetId) {
136
+ if (!this._rulesetVars.has(rulesetId)) {
137
+ const varsManager = new RulesetVariablesManager_1.RulesetVariablesManagerImpl(rulesetId, this._ipcRequestsHandler);
138
+ this._rulesetVars.set(rulesetId, varsManager);
139
+ }
140
+ return this._rulesetVars.get(rulesetId);
141
+ }
142
+ toRpcTokenOptions(requestOptions) {
143
+ // 1. put default `locale` and `unitSystem`
144
+ // 2. put all `requestOptions` members (if `locale` or `unitSystem` are set, they'll override the defaults put at #1)
145
+ // 3. put `imodel` of type `IModelRpcProps` which overwrites the `imodel` from `requestOptions` put at #2
146
+ const defaultOptions = {};
147
+ if (this.activeLocale)
148
+ defaultOptions.locale = this.activeLocale;
149
+ defaultOptions.unitSystem = this.activeUnitSystem; // eslint-disable-line deprecation/deprecation
150
+ const { imodel, rulesetVariables, ...rpcRequestOptions } = requestOptions;
151
+ return {
152
+ ...defaultOptions,
153
+ ...rpcRequestOptions,
154
+ ...(rulesetVariables ? { rulesetVariables: rulesetVariables.map(presentation_common_1.RulesetVariable.toJSON) } : {}),
155
+ imodel: imodel.getRpcProps(),
156
+ };
157
+ }
158
+ async addRulesetAndVariablesToOptions(options) {
159
+ const { rulesetOrId, rulesetVariables } = options;
160
+ let foundRulesetOrId;
161
+ if (typeof rulesetOrId === "object") {
162
+ foundRulesetOrId = rulesetOrId;
163
+ }
164
+ else {
165
+ const foundRuleset = await this._rulesets.get(rulesetOrId);
166
+ foundRulesetOrId = foundRuleset ? foundRuleset.toJSON() : rulesetOrId;
167
+ }
168
+ const rulesetId = (typeof foundRulesetOrId === "object") ? foundRulesetOrId.id : foundRulesetOrId;
169
+ // All Id64Array variable values must be sorted for serialization to JSON to work. RulesetVariablesManager
170
+ // sorts them before storing, so that part is taken care of, but we need to ensure that variables coming from
171
+ // request options are also sorted.
172
+ const variables = (rulesetVariables ?? []).map((variable) => {
173
+ if (variable.type === presentation_common_1.VariableValueTypes.Id64Array)
174
+ return { ...variable, value: core_bentley_1.OrderedId64Iterable.sortArray(variable.value) };
175
+ return variable;
176
+ });
177
+ if (!this._ipcRequestsHandler) {
178
+ // only need to add variables from variables manager if there's no IPC
179
+ // handler - if there is one, the variables are already known by the backend
180
+ variables.push(...this.vars(rulesetId).getAllVariables());
181
+ }
182
+ return { ...options, rulesetOrId: foundRulesetOrId, rulesetVariables: variables };
183
+ }
184
+ /** Retrieves nodes */
185
+ async getNodes(requestOptions) {
186
+ await this.onConnection(requestOptions.imodel);
187
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
188
+ const rpcOptions = this.toRpcTokenOptions({ ...options });
189
+ const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions) => this._requestsHandler.getPagedNodes({ ...rpcOptions, paging: partialPageOptions }));
190
+ // eslint-disable-next-line deprecation/deprecation
191
+ return this._localizationHelper.getLocalizedNodes(result.items.map(presentation_common_1.Node.fromJSON));
192
+ }
193
+ /** Retrieves nodes count. */
194
+ async getNodesCount(requestOptions) {
195
+ await this.onConnection(requestOptions.imodel);
196
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
197
+ const rpcOptions = this.toRpcTokenOptions({ ...options });
198
+ return this._requestsHandler.getNodesCount(rpcOptions);
199
+ }
200
+ /** Retrieves total nodes count and a single page of nodes. */
201
+ async getNodesAndCount(requestOptions) {
202
+ await this.onConnection(requestOptions.imodel);
203
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
204
+ const rpcOptions = this.toRpcTokenOptions({ ...options });
205
+ const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions) => this._requestsHandler.getPagedNodes({ ...rpcOptions, paging: partialPageOptions }));
206
+ return {
207
+ count: result.total,
208
+ // eslint-disable-next-line deprecation/deprecation
209
+ nodes: this._localizationHelper.getLocalizedNodes(result.items.map(presentation_common_1.Node.fromJSON)),
210
+ };
211
+ }
212
+ /**
213
+ * Retrieves hierarchy level descriptor.
214
+ * @beta
215
+ */
216
+ async getNodesDescriptor(requestOptions) {
217
+ await this.onConnection(requestOptions.imodel);
218
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
219
+ const rpcOptions = this.toRpcTokenOptions({ ...options });
220
+ const result = await this._requestsHandler.getNodesDescriptor(rpcOptions);
221
+ return presentation_common_1.Descriptor.fromJSON(result);
222
+ }
223
+ /** Retrieves paths from root nodes to children nodes according to specified keys. Intersecting paths will be merged. */
224
+ async getNodePaths(requestOptions) {
225
+ await this.onConnection(requestOptions.imodel);
226
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
227
+ const rpcOptions = this.toRpcTokenOptions({ ...options });
228
+ const result = await this._requestsHandler.getNodePaths(rpcOptions);
229
+ // eslint-disable-next-line deprecation/deprecation
230
+ return result.map(presentation_common_1.NodePathElement.fromJSON);
231
+ }
232
+ /** Retrieves paths from root nodes to nodes containing filter text in their label. */
233
+ async getFilteredNodePaths(requestOptions) {
234
+ await this.onConnection(requestOptions.imodel);
235
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
236
+ const result = await this._requestsHandler.getFilteredNodePaths(this.toRpcTokenOptions(options));
237
+ // eslint-disable-next-line deprecation/deprecation
238
+ return result.map(presentation_common_1.NodePathElement.fromJSON);
239
+ }
240
+ /**
241
+ * Get information about the sources of content when building it for specific ECClasses. Sources involve classes of the primary select instance,
242
+ * its related instances for loading related and navigation properties.
243
+ * @public
244
+ */
245
+ async getContentSources(requestOptions) {
246
+ await this.onConnection(requestOptions.imodel);
247
+ const rpcOptions = this.toRpcTokenOptions(requestOptions);
248
+ const result = await this._requestsHandler.getContentSources(rpcOptions);
249
+ return presentation_common_1.SelectClassInfo.listFromCompressedJSON(result.sources, result.classesMap);
250
+ }
251
+ /** Retrieves the content descriptor which describes the content and can be used to customize it. */
252
+ async getContentDescriptor(requestOptions) {
253
+ await this.onConnection(requestOptions.imodel);
254
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
255
+ const rpcOptions = this.toRpcTokenOptions({
256
+ ...options,
257
+ keys: stripTransientElementKeys(options.keys).toJSON(),
258
+ });
259
+ const result = await this._requestsHandler.getContentDescriptor(rpcOptions);
260
+ return presentation_common_1.Descriptor.fromJSON(result);
261
+ }
262
+ /** Retrieves overall content set size. */
263
+ async getContentSetSize(requestOptions) {
264
+ await this.onConnection(requestOptions.imodel);
265
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
266
+ const rpcOptions = this.toRpcTokenOptions({
267
+ ...options,
268
+ descriptor: getDescriptorOverrides(requestOptions.descriptor),
269
+ keys: stripTransientElementKeys(requestOptions.keys).toJSON(),
270
+ });
271
+ return this._requestsHandler.getContentSetSize(rpcOptions);
272
+ }
273
+ /** Retrieves content which consists of a content descriptor and a page of records. */
274
+ async getContent(requestOptions) {
275
+ return (await this.getContentAndSize(requestOptions))?.content;
276
+ }
277
+ /** Retrieves content set size and content which consists of a content descriptor and a page of records. */
278
+ 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
+ });
286
+ let descriptor = (requestOptions.descriptor instanceof presentation_common_1.Descriptor) ? requestOptions.descriptor : undefined;
287
+ const result = await (0, exports.buildPagedArrayResponse)(options.paging, async (partialPageOptions, requestIndex) => {
288
+ if (0 === requestIndex && !descriptor) {
289
+ const content = await this._requestsHandler.getPagedContent({ ...rpcOptions, paging: partialPageOptions });
290
+ if (content) {
291
+ descriptor = presentation_common_1.Descriptor.fromJSON(content.descriptor);
292
+ return content.contentSet;
293
+ }
294
+ return { total: 0, items: [] };
295
+ }
296
+ return this._requestsHandler.getPagedContentSet({ ...rpcOptions, paging: partialPageOptions });
297
+ });
298
+ if (!descriptor)
299
+ return undefined;
300
+ const items = result.items.map((itemJson) => presentation_common_1.Item.fromJSON(itemJson)).filter((item) => (item !== undefined));
301
+ return {
302
+ size: result.total,
303
+ content: this._localizationHelper.getLocalizedContent(new presentation_common_1.Content(descriptor, items)),
304
+ };
305
+ }
306
+ /** Retrieves distinct values of specific field from the content. */
307
+ async getPagedDistinctValues(requestOptions) {
308
+ await this.onConnection(requestOptions.imodel);
309
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
310
+ const rpcOptions = {
311
+ ...this.toRpcTokenOptions(options),
312
+ descriptor: getDescriptorOverrides(options.descriptor),
313
+ keys: stripTransientElementKeys(options.keys).toJSON(),
314
+ };
315
+ const result = await (0, exports.buildPagedArrayResponse)(requestOptions.paging, async (partialPageOptions) => this._requestsHandler.getPagedDistinctValues({ ...rpcOptions, paging: partialPageOptions }));
316
+ return {
317
+ ...result,
318
+ // eslint-disable-next-line deprecation/deprecation
319
+ items: result.items.map(presentation_common_1.DisplayValueGroup.fromJSON),
320
+ };
321
+ }
322
+ /**
323
+ * Retrieves property data in a simplified format for a single element specified by ID.
324
+ * @public
325
+ */
326
+ async getElementProperties(requestOptions) {
327
+ await this.onConnection(requestOptions.imodel);
328
+ const results = await this._requestsHandler.getElementProperties(this.toRpcTokenOptions(requestOptions));
329
+ // istanbul ignore if
330
+ if (!results)
331
+ return undefined;
332
+ return this._localizationHelper.getLocalizedElementProperties(results);
333
+ }
334
+ /**
335
+ * Retrieves content item instance keys.
336
+ * @public
337
+ */
338
+ async getContentInstanceKeys(requestOptions) {
339
+ await this.onConnection(requestOptions.imodel);
340
+ const options = await this.addRulesetAndVariablesToOptions(requestOptions);
341
+ const rpcOptions = {
342
+ ...this.toRpcTokenOptions(options),
343
+ keys: stripTransientElementKeys(options.keys).toJSON(),
344
+ };
345
+ const props = {
346
+ page: requestOptions.paging,
347
+ get: async (page) => {
348
+ const keys = await this._requestsHandler.getContentInstanceKeys({ ...rpcOptions, paging: page });
349
+ return {
350
+ total: keys.total,
351
+ items: keys.items.instanceKeys.reduce((instanceKeys, entry) => {
352
+ for (const id of core_bentley_1.CompressedId64Set.iterable(entry[1])) {
353
+ instanceKeys.push({ className: entry[0], id });
354
+ }
355
+ return instanceKeys;
356
+ }, new Array()),
357
+ };
358
+ },
359
+ };
360
+ return createPagedGeneratorResponse(props);
361
+ }
362
+ /** Retrieves display label definition of specific item. */
363
+ async getDisplayLabelDefinition(requestOptions) {
364
+ await this.onConnection(requestOptions.imodel);
365
+ const rpcOptions = this.toRpcTokenOptions({ ...requestOptions });
366
+ const result = await this._requestsHandler.getDisplayLabelDefinition(rpcOptions);
367
+ return this._localizationHelper.getLocalizedLabelDefinition(result);
368
+ }
369
+ /** Retrieves display label definition of specific items. */
370
+ async getDisplayLabelDefinitions(requestOptions) {
371
+ await this.onConnection(requestOptions.imodel);
372
+ const rpcOptions = this.toRpcTokenOptions({ ...requestOptions });
373
+ const result = await (0, exports.buildPagedArrayResponse)(undefined, async (partialPageOptions) => {
374
+ const partialKeys = (!partialPageOptions.start) ? rpcOptions.keys : rpcOptions.keys.slice(partialPageOptions.start);
375
+ return this._requestsHandler.getPagedDisplayLabelDefinitions({ ...rpcOptions, keys: partialKeys });
376
+ });
377
+ return this._localizationHelper.getLocalizedLabelDefinitions(result.items);
378
+ }
379
+ }
380
+ exports.PresentationManager = PresentationManager;
381
+ const getDescriptorOverrides = (descriptorOrOverrides) => {
382
+ if (descriptorOrOverrides instanceof presentation_common_1.Descriptor)
383
+ return descriptorOrOverrides.createDescriptorOverrides();
384
+ return descriptorOrOverrides;
385
+ };
386
+ async function createPagedGeneratorResponse(props) {
387
+ let pageStart = props.page?.start ?? 0;
388
+ let pageSize = props.page?.size ?? 0;
389
+ let requestIndex = 0;
390
+ const firstPage = await props.get({ start: pageStart, size: pageSize }, requestIndex++);
391
+ return {
392
+ total: firstPage.total,
393
+ async *items() {
394
+ let partialResult = firstPage;
395
+ while (true) {
396
+ for (const item of partialResult.items) {
397
+ yield item;
398
+ }
399
+ const receivedItemsCount = partialResult.items.length;
400
+ if (partialResult.total !== 0 && receivedItemsCount === 0) {
401
+ if (pageStart >= partialResult.total)
402
+ throw new Error(`Requested page with start index ${pageStart} is out of bounds. Total number of items: ${partialResult.total}`);
403
+ throw new Error("Paged request returned non zero total count but no items");
404
+ }
405
+ if (pageSize !== 0 && receivedItemsCount >= pageSize || receivedItemsCount >= (partialResult.total - pageStart))
406
+ break;
407
+ if (pageSize !== 0)
408
+ pageSize -= receivedItemsCount;
409
+ pageStart += receivedItemsCount;
410
+ partialResult = await props.get({ start: pageStart, size: pageSize }, requestIndex++);
411
+ }
412
+ },
413
+ };
414
+ }
415
+ /** @internal */
416
+ const buildPagedArrayResponse = async (requestedPage, getter) => {
417
+ const items = new Array();
418
+ const gen = await createPagedGeneratorResponse({ page: requestedPage, get: getter });
419
+ for await (const item of gen.items()) {
420
+ items.push(item);
421
+ }
422
+ return { total: gen.total, items };
423
+ };
424
+ exports.buildPagedArrayResponse = buildPagedArrayResponse;
425
+ const stripTransientElementKeys = (keys) => {
426
+ if (!keys.some((key) => presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME))
427
+ return keys;
428
+ const copy = new presentation_common_1.KeySet();
429
+ copy.add(keys, (key) => {
430
+ // the callback is not going to be called with EntityProps as KeySet converts them
431
+ // to InstanceKeys, but we want to keep the EntityProps case for correctness
432
+ // istanbul ignore next
433
+ const isTransient = presentation_common_1.Key.isInstanceKey(key) && key.className === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME
434
+ || presentation_common_1.Key.isEntityProps(key) && key.classFullName === SelectionManager_1.TRANSIENT_ELEMENT_CLASSNAME;
435
+ return !isTransient;
436
+ });
437
+ return copy;
438
+ };
439
439
  //# sourceMappingURL=PresentationManager.js.map