@itwin/presentation-backend 3.0.0-dev.100

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 (79) hide show
  1. package/CHANGELOG.md +936 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +12 -0
  4. package/lib/cjs/assets/primary-presentation-rules/ElementProperties.PresentationRuleSet.json +14 -0
  5. package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +739 -0
  6. package/lib/cjs/assets/supplemental-presentation-rules/Functional.PresentationRuleSet.json +139 -0
  7. package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +42 -0
  8. package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts.map +1 -0
  9. package/lib/cjs/presentation-backend/BackendLoggerCategory.js +51 -0
  10. package/lib/cjs/presentation-backend/BackendLoggerCategory.js.map +1 -0
  11. package/lib/cjs/presentation-backend/Constants.d.ts +14 -0
  12. package/lib/cjs/presentation-backend/Constants.d.ts.map +1 -0
  13. package/lib/cjs/presentation-backend/Constants.js +44 -0
  14. package/lib/cjs/presentation-backend/Constants.js.map +1 -0
  15. package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +12 -0
  16. package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts.map +1 -0
  17. package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +256 -0
  18. package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -0
  19. package/lib/cjs/presentation-backend/NativePlatform.d.ts +86 -0
  20. package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -0
  21. package/lib/cjs/presentation-backend/NativePlatform.js +153 -0
  22. package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -0
  23. package/lib/cjs/presentation-backend/Presentation.d.ts +98 -0
  24. package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -0
  25. package/lib/cjs/presentation-backend/Presentation.js +135 -0
  26. package/lib/cjs/presentation-backend/Presentation.js.map +1 -0
  27. package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +13 -0
  28. package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts.map +1 -0
  29. package/lib/cjs/presentation-backend/PresentationIpcHandler.js +41 -0
  30. package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -0
  31. package/lib/cjs/presentation-backend/PresentationManager.d.ts +379 -0
  32. package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -0
  33. package/lib/cjs/presentation-backend/PresentationManager.js +635 -0
  34. package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -0
  35. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +58 -0
  36. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -0
  37. package/lib/cjs/presentation-backend/PresentationRpcImpl.js +271 -0
  38. package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -0
  39. package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +105 -0
  40. package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts.map +1 -0
  41. package/lib/cjs/presentation-backend/RulesetEmbedder.js +283 -0
  42. package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -0
  43. package/lib/cjs/presentation-backend/RulesetManager.d.ts +54 -0
  44. package/lib/cjs/presentation-backend/RulesetManager.d.ts.map +1 -0
  45. package/lib/cjs/presentation-backend/RulesetManager.js +74 -0
  46. package/lib/cjs/presentation-backend/RulesetManager.js.map +1 -0
  47. package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +141 -0
  48. package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts.map +1 -0
  49. package/lib/cjs/presentation-backend/RulesetVariablesManager.js +130 -0
  50. package/lib/cjs/presentation-backend/RulesetVariablesManager.js.map +1 -0
  51. package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +38 -0
  52. package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts.map +1 -0
  53. package/lib/cjs/presentation-backend/SelectionScopesHelper.js +257 -0
  54. package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -0
  55. package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +73 -0
  56. package/lib/cjs/presentation-backend/TemporaryStorage.d.ts.map +1 -0
  57. package/lib/cjs/presentation-backend/TemporaryStorage.js +92 -0
  58. package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -0
  59. package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +28 -0
  60. package/lib/cjs/presentation-backend/UpdatesTracker.d.ts.map +1 -0
  61. package/lib/cjs/presentation-backend/UpdatesTracker.js +55 -0
  62. package/lib/cjs/presentation-backend/UpdatesTracker.js.map +1 -0
  63. package/lib/cjs/presentation-backend/Utils.d.ts +11 -0
  64. package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -0
  65. package/lib/cjs/presentation-backend/Utils.js +39 -0
  66. package/lib/cjs/presentation-backend/Utils.js.map +1 -0
  67. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +17 -0
  68. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts.map +1 -0
  69. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +52 -0
  70. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -0
  71. package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +22 -0
  72. package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts.map +1 -0
  73. package/lib/cjs/presentation-backend/domain/RulesetElements.js +39 -0
  74. package/lib/cjs/presentation-backend/domain/RulesetElements.js.map +1 -0
  75. package/lib/cjs/presentation-backend.d.ts +20 -0
  76. package/lib/cjs/presentation-backend.d.ts.map +1 -0
  77. package/lib/cjs/presentation-backend.js +36 -0
  78. package/lib/cjs/presentation-backend.js.map +1 -0
  79. package/package.json +99 -0
@@ -0,0 +1,635 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getKeysForContentRequest = exports.PresentationManager = exports.HierarchyCacheMode = exports.PresentationManagerMode = void 0;
30
+ const hash = __importStar(require("object-hash"));
31
+ const path = __importStar(require("path"));
32
+ const core_backend_1 = require("@itwin/core-backend");
33
+ const presentation_common_1 = require("@itwin/presentation-common");
34
+ const Constants_1 = require("./Constants");
35
+ const ElementPropertiesHelper_1 = require("./ElementPropertiesHelper");
36
+ const NativePlatform_1 = require("./NativePlatform");
37
+ const RulesetManager_1 = require("./RulesetManager");
38
+ const RulesetVariablesManager_1 = require("./RulesetVariablesManager");
39
+ const SelectionScopesHelper_1 = require("./SelectionScopesHelper");
40
+ const UpdatesTracker_1 = require("./UpdatesTracker");
41
+ const Utils_1 = require("./Utils");
42
+ /**
43
+ * Presentation manager working mode.
44
+ * @public
45
+ */
46
+ var PresentationManagerMode;
47
+ (function (PresentationManagerMode) {
48
+ /**
49
+ * Presentation manager assumes iModels are opened in read-only mode and avoids doing some work
50
+ * related to reacting to changes in iModels.
51
+ */
52
+ PresentationManagerMode[PresentationManagerMode["ReadOnly"] = 0] = "ReadOnly";
53
+ /**
54
+ * Presentation manager assumes iModels are opened in read-write mode and it may need to
55
+ * react to changes. This involves some additional work and gives slightly worse performance.
56
+ */
57
+ PresentationManagerMode[PresentationManagerMode["ReadWrite"] = 1] = "ReadWrite";
58
+ })(PresentationManagerMode = exports.PresentationManagerMode || (exports.PresentationManagerMode = {}));
59
+ /**
60
+ * Presentation hierarchy cache mode.
61
+ * @beta
62
+ */
63
+ var HierarchyCacheMode;
64
+ (function (HierarchyCacheMode) {
65
+ /**
66
+ * Hierarchy cache is created in memory.
67
+ */
68
+ HierarchyCacheMode["Memory"] = "memory";
69
+ /**
70
+ * Hierarchy cache is created on disk. In this mode hierarchy cache is persisted between iModel
71
+ * openings.
72
+ */
73
+ HierarchyCacheMode["Disk"] = "disk";
74
+ /**
75
+ * Hierarchy cache is created on disk. In this mode everything is cached in memory while creating hierarchy level
76
+ * and persisted in disk cache when whole hierarchy level is created.
77
+ */
78
+ HierarchyCacheMode["Hybrid"] = "hybrid";
79
+ })(HierarchyCacheMode = exports.HierarchyCacheMode || (exports.HierarchyCacheMode = {}));
80
+ /**
81
+ * Backend Presentation manager which pulls the presentation data from
82
+ * an iModel using native platform.
83
+ *
84
+ * @public
85
+ */
86
+ class PresentationManager {
87
+ /**
88
+ * Creates an instance of PresentationManager.
89
+ * @param props Optional configuration properties.
90
+ */
91
+ constructor(props) {
92
+ var _a, _b, _c, _d, _e;
93
+ // eslint-disable-next-line @typescript-eslint/naming-convention
94
+ this.onIModelOpened = (imodel) => {
95
+ const imodelAddon = this.getNativePlatform().getImodelAddon(imodel);
96
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
97
+ this.getNativePlatform().forceLoadSchemas(imodelAddon);
98
+ };
99
+ /** @internal */
100
+ this.getNativePlatform = () => {
101
+ if (this._isDisposed)
102
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.NotInitialized, "Attempting to use Presentation manager after disposal");
103
+ return this._nativePlatform;
104
+ };
105
+ this._props = props !== null && props !== void 0 ? props : {};
106
+ this._isDisposed = false;
107
+ const mode = (_a = props === null || props === void 0 ? void 0 : props.mode) !== null && _a !== void 0 ? _a : PresentationManagerMode.ReadWrite;
108
+ const isChangeTrackingEnabled = (mode === PresentationManagerMode.ReadWrite && !!(props === null || props === void 0 ? void 0 : props.updatesPollInterval));
109
+ if (props && props.addon) {
110
+ this._nativePlatform = props.addon;
111
+ }
112
+ else {
113
+ const nativePlatformImpl = (0, NativePlatform_1.createDefaultNativePlatform)({
114
+ id: (_b = this._props.id) !== null && _b !== void 0 ? _b : "",
115
+ localeDirectories: createLocaleDirectoryList(props),
116
+ taskAllocationsMap: createTaskAllocationsMap(props),
117
+ mode,
118
+ isChangeTrackingEnabled,
119
+ cacheConfig: createCacheConfig((_c = this._props.caching) === null || _c === void 0 ? void 0 : _c.hierarchies),
120
+ contentCacheSize: (_e = (_d = this._props.caching) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.size,
121
+ defaultFormats: toNativeUnitFormatsMap(this._props.defaultFormats),
122
+ useMmap: this._props.useMmap,
123
+ });
124
+ this._nativePlatform = new nativePlatformImpl();
125
+ }
126
+ this.setupRulesetDirectories(props);
127
+ if (props) {
128
+ this.activeLocale = props.defaultLocale;
129
+ this.activeUnitSystem = props.defaultUnitSystem;
130
+ }
131
+ this._rulesets = new RulesetManager_1.RulesetManagerImpl(this.getNativePlatform);
132
+ if (this._props.enableSchemasPreload)
133
+ this._disposeIModelOpenedListener = core_backend_1.BriefcaseDb.onOpened.addListener(this.onIModelOpened);
134
+ if (core_backend_1.IpcHost.isValid && isChangeTrackingEnabled) {
135
+ this._updatesTracker = UpdatesTracker_1.UpdatesTracker.create({
136
+ nativePlatformGetter: this.getNativePlatform,
137
+ pollInterval: props.updatesPollInterval,
138
+ });
139
+ }
140
+ }
141
+ /**
142
+ * Dispose the presentation manager. Must be called to clean up native resources.
143
+ */
144
+ dispose() {
145
+ if (this._nativePlatform) {
146
+ this.getNativePlatform().dispose();
147
+ this._nativePlatform = undefined;
148
+ }
149
+ if (this._disposeIModelOpenedListener)
150
+ this._disposeIModelOpenedListener();
151
+ if (this._updatesTracker) {
152
+ this._updatesTracker.dispose();
153
+ this._updatesTracker = undefined;
154
+ }
155
+ this._isDisposed = true;
156
+ }
157
+ /** Properties used to initialize the manager */
158
+ get props() { return this._props; }
159
+ /**
160
+ * Get rulesets manager
161
+ */
162
+ rulesets() { return this._rulesets; }
163
+ /**
164
+ * Get ruleset variables manager for specific ruleset
165
+ * @param rulesetId Id of the ruleset to get variables manager for
166
+ */
167
+ vars(rulesetId) {
168
+ return new RulesetVariablesManager_1.RulesetVariablesManagerImpl(this.getNativePlatform, rulesetId);
169
+ }
170
+ setupRulesetDirectories(props) {
171
+ const supplementalRulesetDirectories = [path.join(getPresentationBackendAssetsRoot(props === null || props === void 0 ? void 0 : props.presentationAssetsRoot), "supplemental-presentation-rules")];
172
+ if (props && props.supplementalRulesetDirectories) {
173
+ props.supplementalRulesetDirectories.forEach((dir) => {
174
+ if (-1 === supplementalRulesetDirectories.indexOf(dir))
175
+ supplementalRulesetDirectories.push(dir);
176
+ });
177
+ }
178
+ this.getNativePlatform().setupSupplementalRulesetDirectories(supplementalRulesetDirectories);
179
+ const primaryRulesetDirectories = [path.join(getPresentationBackendAssetsRoot(props === null || props === void 0 ? void 0 : props.presentationAssetsRoot), "primary-presentation-rules")];
180
+ if (props && props.rulesetDirectories) {
181
+ props.rulesetDirectories.forEach((dir) => {
182
+ if (-1 === primaryRulesetDirectories.indexOf(dir))
183
+ primaryRulesetDirectories.push(dir);
184
+ });
185
+ }
186
+ this.getNativePlatform().setupRulesetDirectories(primaryRulesetDirectories);
187
+ }
188
+ getRulesetIdObject(rulesetOrId) {
189
+ if (typeof rulesetOrId === "object") {
190
+ const hashedId = hash.MD5(rulesetOrId);
191
+ return {
192
+ uniqueId: `${rulesetOrId.id}-${hashedId}`,
193
+ parts: {
194
+ id: rulesetOrId.id,
195
+ hash: hashedId,
196
+ },
197
+ };
198
+ }
199
+ return { uniqueId: rulesetOrId, parts: { id: rulesetOrId } };
200
+ }
201
+ /** @internal */
202
+ getRulesetId(rulesetOrId) {
203
+ return this.getRulesetIdObject(rulesetOrId).uniqueId;
204
+ }
205
+ ensureRulesetRegistered(rulesetOrId) {
206
+ if (typeof rulesetOrId === "object") {
207
+ const rulesetWithNativeId = { ...rulesetOrId, id: this.getRulesetId(rulesetOrId) };
208
+ return this.rulesets().add(rulesetWithNativeId).id;
209
+ }
210
+ return rulesetOrId;
211
+ }
212
+ /** Registers given ruleset and replaces the ruleset with its ID in the resulting object */
213
+ registerRuleset(options) {
214
+ const { rulesetOrId, ...strippedOptions } = options;
215
+ const registeredRulesetId = this.ensureRulesetRegistered(rulesetOrId);
216
+ return { rulesetId: registeredRulesetId, strippedOptions };
217
+ }
218
+ /**
219
+ * Retrieves nodes
220
+ * @public
221
+ */
222
+ async getNodes(requestOptions) {
223
+ const { rulesetId, strippedOptions: { parentKey, ...strippedOptions } } = this.registerRuleset(requestOptions);
224
+ const params = {
225
+ requestId: parentKey ? NativePlatform_1.NativePlatformRequestTypes.GetChildren : NativePlatform_1.NativePlatformRequestTypes.GetRootNodes,
226
+ rulesetId,
227
+ ...strippedOptions,
228
+ nodeKey: parentKey,
229
+ };
230
+ return this.request(params, presentation_common_1.Node.listReviver);
231
+ }
232
+ /**
233
+ * Retrieves nodes count
234
+ * @public
235
+ */
236
+ async getNodesCount(requestOptions) {
237
+ const { rulesetId, strippedOptions: { parentKey, ...strippedOptions } } = this.registerRuleset(requestOptions);
238
+ const params = {
239
+ requestId: parentKey ? NativePlatform_1.NativePlatformRequestTypes.GetChildrenCount : NativePlatform_1.NativePlatformRequestTypes.GetRootNodesCount,
240
+ rulesetId,
241
+ ...strippedOptions,
242
+ nodeKey: parentKey,
243
+ };
244
+ return this.request(params);
245
+ }
246
+ /**
247
+ * Retrieves paths from root nodes to children nodes according to specified instance key paths. Intersecting paths will be merged.
248
+ * TODO: Return results in pages
249
+ * @public
250
+ */
251
+ async getNodePaths(requestOptions) {
252
+ const { rulesetId, strippedOptions: { instancePaths, ...strippedOptions } } = this.registerRuleset(requestOptions);
253
+ const params = {
254
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetNodePaths,
255
+ rulesetId,
256
+ ...strippedOptions,
257
+ paths: instancePaths.map((p) => p.map((s) => presentation_common_1.InstanceKey.toJSON(s))),
258
+ };
259
+ return this.request(params, presentation_common_1.NodePathElement.listReviver);
260
+ }
261
+ /**
262
+ * Retrieves paths from root nodes to nodes containing filter text in their label.
263
+ * TODO: Return results in pages
264
+ * @public
265
+ */
266
+ async getFilteredNodePaths(requestOptions) {
267
+ const { rulesetId, strippedOptions } = this.registerRuleset(requestOptions);
268
+ const params = {
269
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetFilteredNodePaths,
270
+ rulesetId,
271
+ ...strippedOptions,
272
+ };
273
+ return this.request(params, presentation_common_1.NodePathElement.listReviver);
274
+ }
275
+ /** @beta */
276
+ async getContentSources(requestOptions) {
277
+ const params = {
278
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetContentSources,
279
+ rulesetId: "ElementProperties",
280
+ ...requestOptions,
281
+ };
282
+ const reviver = (key, value) => {
283
+ return key === "" ? presentation_common_1.SelectClassInfo.listFromCompressedJSON(value.sources, value.classesMap) : value;
284
+ };
285
+ return this.request(params, reviver);
286
+ }
287
+ /**
288
+ * Retrieves the content descriptor which can be used to get content
289
+ * @public
290
+ */
291
+ async getContentDescriptor(requestOptions) {
292
+ const { rulesetId, strippedOptions } = this.registerRuleset(requestOptions);
293
+ const params = {
294
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetContentDescriptor,
295
+ rulesetId,
296
+ ...strippedOptions,
297
+ keys: getKeysForContentRequest(requestOptions.keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
298
+ };
299
+ const reviver = (key, value) => {
300
+ return key === "" ? presentation_common_1.Descriptor.fromJSON(value) : value;
301
+ };
302
+ return this.request(params, reviver);
303
+ }
304
+ /**
305
+ * Retrieves the content set size based on the supplied content descriptor override
306
+ * @public
307
+ */
308
+ async getContentSetSize(requestOptions) {
309
+ const { rulesetId, strippedOptions: { descriptor, ...strippedOptions } } = this.registerRuleset(requestOptions);
310
+ const params = {
311
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetContentSetSize,
312
+ rulesetId,
313
+ ...strippedOptions,
314
+ keys: getKeysForContentRequest(requestOptions.keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
315
+ descriptorOverrides: createContentDescriptorOverrides(descriptor),
316
+ };
317
+ return this.request(params);
318
+ }
319
+ /**
320
+ * Retrieves the content based on the supplied content descriptor override.
321
+ * @public
322
+ */
323
+ async getContent(requestOptions) {
324
+ const { rulesetId, strippedOptions: { descriptor, ...strippedOptions } } = this.registerRuleset(requestOptions);
325
+ const params = {
326
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetContent,
327
+ rulesetId,
328
+ ...strippedOptions,
329
+ keys: getKeysForContentRequest(requestOptions.keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
330
+ descriptorOverrides: createContentDescriptorOverrides(descriptor),
331
+ };
332
+ return this.request(params, presentation_common_1.Content.reviver);
333
+ }
334
+ /**
335
+ * Retrieves distinct values of specific field from the content based on the supplied content descriptor override.
336
+ * @param requestOptions Options for the request
337
+ * @return A promise object that returns either distinct values on success or an error string on error.
338
+ * @public
339
+ */
340
+ async getPagedDistinctValues(requestOptions) {
341
+ const { rulesetId, strippedOptions } = this.registerRuleset(requestOptions);
342
+ const { descriptor, keys, ...strippedOptionsNoDescriptorAndKeys } = strippedOptions;
343
+ const params = {
344
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetPagedDistinctValues,
345
+ rulesetId,
346
+ ...strippedOptionsNoDescriptorAndKeys,
347
+ keys: getKeysForContentRequest(keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
348
+ descriptorOverrides: createContentDescriptorOverrides(descriptor),
349
+ };
350
+ const reviver = (key, value) => {
351
+ return key === "" ? {
352
+ total: value.total,
353
+ items: value.items.map(presentation_common_1.DisplayValueGroup.fromJSON),
354
+ } : value;
355
+ };
356
+ return this.request(params, reviver);
357
+ }
358
+ async getElementProperties(requestOptions) {
359
+ if ((0, presentation_common_1.isSingleElementPropertiesRequestOptions)(requestOptions)) {
360
+ const { elementId, ...optionsNoElementId } = requestOptions;
361
+ const content = await this.getContent({
362
+ ...optionsNoElementId,
363
+ descriptor: {
364
+ displayType: presentation_common_1.DefaultContentDisplayTypes.PropertyPane,
365
+ contentFlags: presentation_common_1.ContentFlags.ShowLabels,
366
+ },
367
+ rulesetOrId: "ElementProperties",
368
+ keys: new presentation_common_1.KeySet([{ className: "BisCore:Element", id: elementId }]),
369
+ });
370
+ const properties = (0, ElementPropertiesHelper_1.buildElementsProperties)(content);
371
+ return properties[0];
372
+ }
373
+ return this.getMultipleElementProperties(requestOptions);
374
+ }
375
+ async getMultipleElementProperties(requestOptions) {
376
+ const { elementClasses, paging, ...optionsNoElementClasses } = requestOptions;
377
+ const elementsCount = (0, ElementPropertiesHelper_1.getElementsCount)(requestOptions.imodel, requestOptions.elementClasses);
378
+ const elementIds = (0, ElementPropertiesHelper_1.getElementIdsByClass)(requestOptions.imodel, elementClasses, paging);
379
+ const elementProperties = [];
380
+ for (const entry of elementIds) {
381
+ const properties = await buildElementsPropertiesInPages(entry[0], entry[1], async (keys) => {
382
+ const content = await this.getContent({
383
+ ...optionsNoElementClasses,
384
+ descriptor: {
385
+ displayType: presentation_common_1.DefaultContentDisplayTypes.PropertyPane,
386
+ contentFlags: presentation_common_1.ContentFlags.ShowLabels,
387
+ },
388
+ rulesetOrId: "ElementProperties",
389
+ keys,
390
+ });
391
+ return (0, ElementPropertiesHelper_1.buildElementsProperties)(content);
392
+ });
393
+ elementProperties.push(...properties);
394
+ }
395
+ return { total: elementsCount, items: elementProperties };
396
+ }
397
+ /**
398
+ * Retrieves display label definition of specific item
399
+ * @public
400
+ */
401
+ async getDisplayLabelDefinition(requestOptions) {
402
+ const params = {
403
+ requestId: NativePlatform_1.NativePlatformRequestTypes.GetDisplayLabel,
404
+ ...requestOptions,
405
+ key: presentation_common_1.InstanceKey.toJSON(requestOptions.key),
406
+ };
407
+ return this.request(params, presentation_common_1.LabelDefinition.reviver);
408
+ }
409
+ /**
410
+ * Retrieves display label definitions of specific items
411
+ * @public
412
+ */
413
+ async getDisplayLabelDefinitions(requestOptions) {
414
+ const concreteKeys = requestOptions.keys.map((k) => {
415
+ if (k.className === "BisCore:Element")
416
+ return (0, Utils_1.getElementKey)(requestOptions.imodel, k.id);
417
+ return k;
418
+ }).filter((k) => !!k);
419
+ const contentRequestOptions = {
420
+ ...requestOptions,
421
+ rulesetOrId: "RulesDrivenECPresentationManager_RulesetId_DisplayLabel",
422
+ descriptor: {
423
+ displayType: presentation_common_1.DefaultContentDisplayTypes.List,
424
+ contentFlags: presentation_common_1.ContentFlags.ShowLabels | presentation_common_1.ContentFlags.NoFields,
425
+ },
426
+ keys: new presentation_common_1.KeySet(concreteKeys),
427
+ };
428
+ const content = await this.getContent(contentRequestOptions);
429
+ return concreteKeys.map((key) => {
430
+ const item = content ? content.contentSet.find((it) => it.primaryKeys.length > 0 && presentation_common_1.InstanceKey.compare(it.primaryKeys[0], key) === 0) : undefined;
431
+ if (!item)
432
+ return { displayValue: "", rawValue: "", typeName: "" };
433
+ return item.label;
434
+ });
435
+ }
436
+ /**
437
+ * Retrieves available selection scopes.
438
+ * @public
439
+ */
440
+ async getSelectionScopes(_requestOptions) {
441
+ return SelectionScopesHelper_1.SelectionScopesHelper.getSelectionScopes();
442
+ }
443
+ /**
444
+ * Computes selection set based on provided selection scope.
445
+ * @public
446
+ */
447
+ async computeSelection(requestOptions) {
448
+ const { ids, scopeId, ...opts } = requestOptions; // eslint-disable-line @typescript-eslint/no-unused-vars
449
+ return SelectionScopesHelper_1.SelectionScopesHelper.computeSelection(opts, ids, scopeId);
450
+ }
451
+ async request(params, reviver) {
452
+ const { requestId, imodel, locale, unitSystem, diagnostics, ...strippedParams } = params;
453
+ const imodelAddon = this.getNativePlatform().getImodelAddon(imodel);
454
+ const nativeRequestParams = {
455
+ requestId,
456
+ params: {
457
+ locale: normalizeLocale(locale !== null && locale !== void 0 ? locale : this.activeLocale),
458
+ unitSystem: toOptionalNativeUnitSystem(unitSystem !== null && unitSystem !== void 0 ? unitSystem : this.activeUnitSystem),
459
+ ...strippedParams,
460
+ },
461
+ };
462
+ let diagnosticsListener;
463
+ if (diagnostics) {
464
+ const { handler: tempDiagnosticsListener, ...diagnosticsOptions } = diagnostics;
465
+ diagnosticsListener = tempDiagnosticsListener;
466
+ nativeRequestParams.params.diagnostics = diagnosticsOptions;
467
+ }
468
+ const response = await this.getNativePlatform().handleRequest(imodelAddon, JSON.stringify(nativeRequestParams));
469
+ diagnosticsListener && response.diagnostics && diagnosticsListener([response.diagnostics]);
470
+ return JSON.parse(response.result, reviver);
471
+ }
472
+ /**
473
+ * Compares two hierarchies specified in the request options
474
+ * @public
475
+ */
476
+ async compareHierarchies(requestOptions) {
477
+ var _a, _b;
478
+ if (!requestOptions.prev.rulesetOrId && !requestOptions.prev.rulesetVariables)
479
+ return { changes: [] };
480
+ const { strippedOptions: { prev, rulesetVariables, ...options } } = this.registerRuleset(requestOptions);
481
+ const currRulesetId = this.getRulesetIdObject(requestOptions.rulesetOrId);
482
+ const prevRulesetId = prev.rulesetOrId ? this.getRulesetIdObject(prev.rulesetOrId) : currRulesetId;
483
+ if (prevRulesetId.parts.id !== currRulesetId.parts.id)
484
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "Can't compare rulesets with different IDs");
485
+ const currRulesetVariables = rulesetVariables !== null && rulesetVariables !== void 0 ? rulesetVariables : [];
486
+ const prevRulesetVariables = (_a = prev.rulesetVariables) !== null && _a !== void 0 ? _a : currRulesetVariables;
487
+ const params = {
488
+ requestId: NativePlatform_1.NativePlatformRequestTypes.CompareHierarchies,
489
+ ...options,
490
+ prevRulesetId: prevRulesetId.uniqueId,
491
+ currRulesetId: currRulesetId.uniqueId,
492
+ prevRulesetVariables: JSON.stringify(prevRulesetVariables),
493
+ currRulesetVariables: JSON.stringify(currRulesetVariables),
494
+ expandedNodeKeys: JSON.stringify((_b = options.expandedNodeKeys) !== null && _b !== void 0 ? _b : []),
495
+ };
496
+ return this.request(params, (key, value) => ((key === "") ? presentation_common_1.HierarchyCompareInfo.fromJSON(value) : value));
497
+ }
498
+ }
499
+ exports.PresentationManager = PresentationManager;
500
+ function addInstanceKey(classInstancesMap, key) {
501
+ let set = classInstancesMap.get(key.className);
502
+ // istanbul ignore else
503
+ if (!set) {
504
+ set = new Set();
505
+ classInstancesMap.set(key.className, set);
506
+ }
507
+ set.add(key.id);
508
+ }
509
+ function bisElementInstanceKeysProcessor(imodel, classInstancesMap) {
510
+ const elementClassName = "BisCore:Element";
511
+ const elementIds = classInstancesMap.get(elementClassName);
512
+ if (elementIds) {
513
+ const deleteElementIds = new Array();
514
+ elementIds.forEach((elementId) => {
515
+ const concreteKey = (0, Utils_1.getElementKey)(imodel, elementId);
516
+ if (concreteKey && concreteKey.className !== elementClassName) {
517
+ deleteElementIds.push(elementId);
518
+ addInstanceKey(classInstancesMap, { className: concreteKey.className, id: elementId });
519
+ }
520
+ });
521
+ for (const id of deleteElementIds)
522
+ elementIds.delete(id);
523
+ }
524
+ }
525
+ /** @internal */
526
+ function getKeysForContentRequest(keys, classInstanceKeysProcessor) {
527
+ const result = {
528
+ instanceKeys: [],
529
+ nodeKeys: [],
530
+ };
531
+ const classInstancesMap = new Map();
532
+ keys.forEach((key) => {
533
+ if (presentation_common_1.Key.isNodeKey(key))
534
+ result.nodeKeys.push(key);
535
+ if (presentation_common_1.Key.isInstanceKey(key))
536
+ addInstanceKey(classInstancesMap, key);
537
+ });
538
+ if (classInstanceKeysProcessor)
539
+ classInstanceKeysProcessor(classInstancesMap);
540
+ for (const entry of classInstancesMap) {
541
+ if (entry[1].size > 0)
542
+ result.instanceKeys.push([entry["0"], [...entry[1]]]);
543
+ }
544
+ return result;
545
+ }
546
+ exports.getKeysForContentRequest = getKeysForContentRequest;
547
+ const createContentDescriptorOverrides = (descriptorOrOverrides) => {
548
+ if (descriptorOrOverrides instanceof presentation_common_1.Descriptor)
549
+ return descriptorOrOverrides.createDescriptorOverrides();
550
+ return descriptorOrOverrides;
551
+ };
552
+ const createLocaleDirectoryList = (props) => {
553
+ const localeDirectories = [(0, presentation_common_1.getLocalesDirectory)(getPresentationCommonAssetsRoot(props === null || props === void 0 ? void 0 : props.presentationAssetsRoot))];
554
+ if (props && props.localeDirectories) {
555
+ props.localeDirectories.forEach((dir) => {
556
+ if (-1 === localeDirectories.indexOf(dir))
557
+ localeDirectories.push(dir);
558
+ });
559
+ }
560
+ return localeDirectories;
561
+ };
562
+ const createTaskAllocationsMap = (props) => {
563
+ var _a;
564
+ const count = (_a = props === null || props === void 0 ? void 0 : props.workerThreadsCount) !== null && _a !== void 0 ? _a : 2;
565
+ return {
566
+ [Number.MAX_SAFE_INTEGER]: count,
567
+ };
568
+ };
569
+ const normalizeLocale = (locale) => {
570
+ if (!locale)
571
+ return undefined;
572
+ return locale.toLocaleLowerCase();
573
+ };
574
+ const normalizeDirectory = (directory) => {
575
+ return directory ? path.resolve(directory) : "";
576
+ };
577
+ const toNativeUnitSystem = (unitSystem) => {
578
+ switch (unitSystem) {
579
+ case "imperial": return NativePlatform_1.NativePresentationUnitSystem.BritishImperial;
580
+ case "metric": return NativePlatform_1.NativePresentationUnitSystem.Metric;
581
+ case "usCustomary": return NativePlatform_1.NativePresentationUnitSystem.UsCustomary;
582
+ case "usSurvey": return NativePlatform_1.NativePresentationUnitSystem.UsSurvey;
583
+ }
584
+ };
585
+ const toOptionalNativeUnitSystem = (unitSystem) => {
586
+ return unitSystem ? toNativeUnitSystem(unitSystem) : undefined;
587
+ };
588
+ const toNativeUnitFormatsMap = (map) => {
589
+ if (!map)
590
+ return undefined;
591
+ const nativeFormatsMap = {};
592
+ Object.keys(map).forEach((phenomenon) => {
593
+ const unitSystemsFormat = map[phenomenon];
594
+ nativeFormatsMap[phenomenon] = {
595
+ unitSystems: unitSystemsFormat.unitSystems.map(toNativeUnitSystem),
596
+ format: unitSystemsFormat.format,
597
+ };
598
+ });
599
+ return nativeFormatsMap;
600
+ };
601
+ const createCacheConfig = (config) => {
602
+ if ((config === null || config === void 0 ? void 0 : config.mode) === HierarchyCacheMode.Disk)
603
+ return { ...config, directory: normalizeDirectory(config.directory) };
604
+ if ((config === null || config === void 0 ? void 0 : config.mode) === HierarchyCacheMode.Hybrid)
605
+ return { ...config, disk: config.disk ? { ...config.disk, directory: normalizeDirectory(config.disk.directory) } : undefined };
606
+ if ((config === null || config === void 0 ? void 0 : config.mode) === HierarchyCacheMode.Memory)
607
+ return config;
608
+ return { mode: HierarchyCacheMode.Disk, directory: "" };
609
+ };
610
+ const getPresentationBackendAssetsRoot = (ovr) => {
611
+ if (typeof ovr === "string")
612
+ return ovr;
613
+ if (typeof ovr === "object")
614
+ return ovr.backend;
615
+ return Constants_1.PRESENTATION_BACKEND_ASSETS_ROOT;
616
+ };
617
+ const getPresentationCommonAssetsRoot = (ovr) => {
618
+ if (typeof ovr === "string")
619
+ return ovr;
620
+ if (typeof ovr === "object")
621
+ return ovr.common;
622
+ return Constants_1.PRESENTATION_COMMON_ASSETS_ROOT;
623
+ };
624
+ const ELEMENT_PROPERTIES_CONTENT_BATCH_SIZE = 100;
625
+ async function buildElementsPropertiesInPages(className, ids, getter) {
626
+ const elementProperties = [];
627
+ const elementIds = [...ids];
628
+ while (elementIds.length > 0) {
629
+ const idsPage = elementIds.splice(0, ELEMENT_PROPERTIES_CONTENT_BATCH_SIZE);
630
+ const keys = new presentation_common_1.KeySet(idsPage.map((id) => ({ id, className })));
631
+ elementProperties.push(...(await getter(keys)));
632
+ }
633
+ return elementProperties;
634
+ }
635
+ //# sourceMappingURL=PresentationManager.js.map