@itwin/presentation-backend 3.3.0-dev.8 → 3.3.0-dev.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/lib/cjs/presentation-backend/NativePlatform.d.ts +2 -2
  3. package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -1
  4. package/lib/cjs/presentation-backend/NativePlatform.js +5 -16
  5. package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
  6. package/lib/cjs/presentation-backend/PresentationManager.d.ts +32 -40
  7. package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
  8. package/lib/cjs/presentation-backend/PresentationManager.js +65 -322
  9. package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
  10. package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +50 -0
  11. package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts.map +1 -0
  12. package/lib/cjs/presentation-backend/PresentationManagerDetail.js +277 -0
  13. package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -0
  14. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +3 -2
  15. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
  16. package/lib/cjs/presentation-backend/PresentationRpcImpl.js +48 -13
  17. package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
  18. package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +5 -7
  19. package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts.map +1 -1
  20. package/lib/cjs/presentation-backend/SelectionScopesHelper.js +60 -87
  21. package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
  22. package/lib/cjs/presentation-backend/Utils.d.ts +13 -2
  23. package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -1
  24. package/lib/cjs/presentation-backend/Utils.js +2 -2
  25. package/lib/cjs/presentation-backend/Utils.js.map +1 -1
  26. package/package.json +17 -17
@@ -6,38 +6,14 @@
6
6
  /** @packageDocumentation
7
7
  * @module Core
8
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
9
  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");
10
+ exports.PresentationManager = exports.HierarchyCacheMode = exports.PresentationManagerMode = void 0;
33
11
  const presentation_common_1 = require("@itwin/presentation-common");
34
- const Constants_1 = require("./Constants");
35
12
  const ElementPropertiesHelper_1 = require("./ElementPropertiesHelper");
36
13
  const NativePlatform_1 = require("./NativePlatform");
37
- const RulesetManager_1 = require("./RulesetManager");
14
+ const PresentationManagerDetail_1 = require("./PresentationManagerDetail");
38
15
  const RulesetVariablesManager_1 = require("./RulesetVariablesManager");
39
16
  const SelectionScopesHelper_1 = require("./SelectionScopesHelper");
40
- const UpdatesTracker_1 = require("./UpdatesTracker");
41
17
  const Utils_1 = require("./Utils");
42
18
  /**
43
19
  * Presentation manager working mode.
@@ -89,71 +65,32 @@ class PresentationManager {
89
65
  * @param props Optional configuration properties.
90
66
  */
91
67
  constructor(props) {
92
- var _a, _b, _c, _d, _e;
93
68
  /** @internal */
94
69
  this.getNativePlatform = () => {
95
- if (this._isDisposed)
96
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.NotInitialized, "Attempting to use Presentation manager after disposal");
97
- return this._nativePlatform;
70
+ return this._detail.getNativePlatform();
98
71
  };
99
72
  this._props = props !== null && props !== void 0 ? props : {};
100
- this._isDisposed = false;
101
- const mode = (_a = props === null || props === void 0 ? void 0 : props.mode) !== null && _a !== void 0 ? _a : PresentationManagerMode.ReadWrite;
102
- const isChangeTrackingEnabled = (mode === PresentationManagerMode.ReadWrite && !!(props === null || props === void 0 ? void 0 : props.updatesPollInterval));
103
- if (props && props.addon) {
104
- this._nativePlatform = props.addon;
105
- }
106
- else {
107
- const nativePlatformImpl = (0, NativePlatform_1.createDefaultNativePlatform)({
108
- id: (_b = this._props.id) !== null && _b !== void 0 ? _b : "",
109
- localeDirectories: createLocaleDirectoryList(props),
110
- taskAllocationsMap: createTaskAllocationsMap(props),
111
- mode,
112
- isChangeTrackingEnabled,
113
- cacheConfig: createCacheConfig((_c = this._props.caching) === null || _c === void 0 ? void 0 : _c.hierarchies),
114
- contentCacheSize: (_e = (_d = this._props.caching) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.size,
115
- defaultFormats: toNativeUnitFormatsMap(this._props.defaultFormats),
116
- useMmap: this._props.useMmap,
117
- });
118
- this._nativePlatform = new nativePlatformImpl();
119
- }
120
- this.setupRulesetDirectories(props);
121
- if (props) {
122
- this.activeLocale = props.defaultLocale;
123
- this.activeUnitSystem = props.defaultUnitSystem;
124
- }
125
- this._rulesets = new RulesetManager_1.RulesetManagerImpl(this.getNativePlatform);
126
- if (core_backend_1.IpcHost.isValid && isChangeTrackingEnabled) {
127
- this._updatesTracker = UpdatesTracker_1.UpdatesTracker.create({
128
- nativePlatformGetter: this.getNativePlatform,
129
- pollInterval: props.updatesPollInterval,
130
- });
131
- }
132
- }
133
- /**
134
- * Dispose the presentation manager. Must be called to clean up native resources.
135
- */
73
+ this._detail = new PresentationManagerDetail_1.PresentationManagerDetail(this._props);
74
+ }
75
+ /** Get / set active locale used for localizing presentation data */
76
+ get activeLocale() { return this._detail.activeLocale; }
77
+ set activeLocale(value) { this._detail.activeLocale = value; }
78
+ /** Get / set active unit system used to format property values with units */
79
+ get activeUnitSystem() { return this._detail.activeUnitSystem; }
80
+ // istanbul ignore next
81
+ set activeUnitSystem(value) { this._detail.activeUnitSystem = value; }
82
+ /** Dispose the presentation manager. Must be called to clean up native resources. */
136
83
  dispose() {
137
- if (this._nativePlatform) {
138
- this.getNativePlatform().dispose();
139
- this._nativePlatform = undefined;
140
- }
141
- if (this._updatesTracker) {
142
- this._updatesTracker.dispose();
143
- this._updatesTracker = undefined;
144
- }
145
- this._isDisposed = true;
84
+ this._detail.dispose();
146
85
  }
147
86
  /** @internal */
148
87
  setOnManagerUsedHandler(handler) {
149
- this._onManagerUsed = handler;
88
+ this._detail.setOnManagerUsedHandler(handler);
150
89
  }
151
90
  /** Properties used to initialize the manager */
152
91
  get props() { return this._props; }
153
- /**
154
- * Get rulesets manager
155
- */
156
- rulesets() { return this._rulesets; }
92
+ /** Get rulesets manager */
93
+ rulesets() { return this._detail.rulesets; }
157
94
  /**
158
95
  * Get ruleset variables manager for specific ruleset
159
96
  * @param rulesetId Id of the ruleset to get variables manager for
@@ -161,89 +98,42 @@ class PresentationManager {
161
98
  vars(rulesetId) {
162
99
  return new RulesetVariablesManager_1.RulesetVariablesManagerImpl(this.getNativePlatform, rulesetId);
163
100
  }
164
- setupRulesetDirectories(props) {
165
- const supplementalRulesetDirectories = [path.join(getPresentationBackendAssetsRoot(props === null || props === void 0 ? void 0 : props.presentationAssetsRoot), "supplemental-presentation-rules")];
166
- if (props && props.supplementalRulesetDirectories) {
167
- props.supplementalRulesetDirectories.forEach((dir) => {
168
- if (-1 === supplementalRulesetDirectories.indexOf(dir))
169
- supplementalRulesetDirectories.push(dir);
170
- });
171
- }
172
- this.getNativePlatform().setupSupplementalRulesetDirectories(supplementalRulesetDirectories);
173
- const primaryRulesetDirectories = [path.join(getPresentationBackendAssetsRoot(props === null || props === void 0 ? void 0 : props.presentationAssetsRoot), "primary-presentation-rules")];
174
- if (props && props.rulesetDirectories) {
175
- props.rulesetDirectories.forEach((dir) => {
176
- if (-1 === primaryRulesetDirectories.indexOf(dir))
177
- primaryRulesetDirectories.push(dir);
178
- });
179
- }
180
- this.getNativePlatform().setupRulesetDirectories(primaryRulesetDirectories);
181
- }
182
- getRulesetIdObject(rulesetOrId) {
183
- if (typeof rulesetOrId === "object") {
184
- if (core_backend_1.IpcHost.isValid) {
185
- // in case of native apps we don't want to enforce ruleset id uniqueness as ruleset variables
186
- // are stored on a backend and creating new id will lose those variables
187
- return {
188
- uniqueId: rulesetOrId.id,
189
- parts: { id: rulesetOrId.id },
190
- };
191
- }
192
- const hashedId = hash.MD5(rulesetOrId);
193
- return {
194
- uniqueId: `${rulesetOrId.id}-${hashedId}`,
195
- parts: {
196
- id: rulesetOrId.id,
197
- hash: hashedId,
198
- },
199
- };
200
- }
201
- return { uniqueId: rulesetOrId, parts: { id: rulesetOrId } };
101
+ /** @internal */
102
+ // istanbul ignore next
103
+ getDetail() {
104
+ return this._detail;
202
105
  }
203
106
  /** @internal */
204
107
  getRulesetId(rulesetOrId) {
205
- return this.getRulesetIdObject(rulesetOrId).uniqueId;
206
- }
207
- ensureRulesetRegistered(rulesetOrId) {
208
- if (typeof rulesetOrId === "object") {
209
- const rulesetWithNativeId = { ...rulesetOrId, id: this.getRulesetId(rulesetOrId) };
210
- return this.rulesets().add(rulesetWithNativeId).id;
211
- }
212
- return rulesetOrId;
213
- }
214
- /** Registers given ruleset and replaces the ruleset with its ID in the resulting object */
215
- registerRuleset(options) {
216
- const { rulesetOrId, ...strippedOptions } = options;
217
- const registeredRulesetId = this.ensureRulesetRegistered(rulesetOrId);
218
- return { rulesetId: registeredRulesetId, strippedOptions };
108
+ return this._detail.getRulesetId(rulesetOrId);
219
109
  }
220
110
  /**
221
111
  * Retrieves nodes
222
112
  * @public
223
113
  */
224
114
  async getNodes(requestOptions) {
225
- const { rulesetId, strippedOptions: { parentKey, ...strippedOptions } } = this.registerRuleset(requestOptions);
115
+ const { rulesetOrId, parentKey, ...strippedOptions } = requestOptions;
226
116
  const params = {
227
117
  requestId: parentKey ? NativePlatform_1.NativePlatformRequestTypes.GetChildren : NativePlatform_1.NativePlatformRequestTypes.GetRootNodes,
228
- rulesetId,
118
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
229
119
  ...strippedOptions,
230
120
  nodeKey: parentKey,
231
121
  };
232
- return this.request(params, presentation_common_1.Node.listReviver);
122
+ return JSON.parse(await this._detail.request(params), presentation_common_1.Node.listReviver);
233
123
  }
234
124
  /**
235
125
  * Retrieves nodes count
236
126
  * @public
237
127
  */
238
128
  async getNodesCount(requestOptions) {
239
- const { rulesetId, strippedOptions: { parentKey, ...strippedOptions } } = this.registerRuleset(requestOptions);
129
+ const { rulesetOrId, parentKey, ...strippedOptions } = requestOptions;
240
130
  const params = {
241
131
  requestId: parentKey ? NativePlatform_1.NativePlatformRequestTypes.GetChildrenCount : NativePlatform_1.NativePlatformRequestTypes.GetRootNodesCount,
242
- rulesetId,
132
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
243
133
  ...strippedOptions,
244
134
  nodeKey: parentKey,
245
135
  };
246
- return this.request(params);
136
+ return JSON.parse(await this._detail.request(params));
247
137
  }
248
138
  /**
249
139
  * Retrieves paths from root nodes to children nodes according to specified instance key paths. Intersecting paths will be merged.
@@ -251,14 +141,14 @@ class PresentationManager {
251
141
  * @public
252
142
  */
253
143
  async getNodePaths(requestOptions) {
254
- const { rulesetId, strippedOptions: { instancePaths, ...strippedOptions } } = this.registerRuleset(requestOptions);
144
+ const { rulesetOrId, instancePaths, ...strippedOptions } = requestOptions;
255
145
  const params = {
256
146
  requestId: NativePlatform_1.NativePlatformRequestTypes.GetNodePaths,
257
- rulesetId,
147
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
258
148
  ...strippedOptions,
259
149
  paths: instancePaths.map((p) => p.map((s) => presentation_common_1.InstanceKey.toJSON(s))),
260
150
  };
261
- return this.request(params, presentation_common_1.NodePathElement.listReviver);
151
+ return JSON.parse(await this._detail.request(params), presentation_common_1.NodePathElement.listReviver);
262
152
  }
263
153
  /**
264
154
  * Retrieves paths from root nodes to nodes containing filter text in their label.
@@ -266,13 +156,13 @@ class PresentationManager {
266
156
  * @public
267
157
  */
268
158
  async getFilteredNodePaths(requestOptions) {
269
- const { rulesetId, strippedOptions } = this.registerRuleset(requestOptions);
159
+ const { rulesetOrId, ...strippedOptions } = requestOptions;
270
160
  const params = {
271
161
  requestId: NativePlatform_1.NativePlatformRequestTypes.GetFilteredNodePaths,
272
- rulesetId,
162
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
273
163
  ...strippedOptions,
274
164
  };
275
- return this.request(params, presentation_common_1.NodePathElement.listReviver);
165
+ return JSON.parse(await this._detail.request(params), presentation_common_1.NodePathElement.listReviver);
276
166
  }
277
167
  /** @beta */
278
168
  async getContentSources(requestOptions) {
@@ -284,54 +174,46 @@ class PresentationManager {
284
174
  const reviver = (key, value) => {
285
175
  return key === "" ? presentation_common_1.SelectClassInfo.listFromCompressedJSON(value.sources, value.classesMap) : value;
286
176
  };
287
- return this.request(params, reviver);
177
+ return JSON.parse(await this._detail.request(params), reviver);
288
178
  }
289
179
  /**
290
180
  * Retrieves the content descriptor which can be used to get content
291
181
  * @public
292
182
  */
293
183
  async getContentDescriptor(requestOptions) {
294
- const { rulesetId, strippedOptions } = this.registerRuleset(requestOptions);
295
- const params = {
296
- requestId: NativePlatform_1.NativePlatformRequestTypes.GetContentDescriptor,
297
- rulesetId,
298
- ...strippedOptions,
299
- keys: getKeysForContentRequest(requestOptions.keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
300
- };
301
- const reviver = (key, value) => {
302
- return key === "" ? presentation_common_1.Descriptor.fromJSON(value) : value;
303
- };
304
- return this.request(params, reviver);
184
+ const response = await this._detail.getContentDescriptor(requestOptions);
185
+ const reviver = (key, value) => key === "" ? presentation_common_1.Descriptor.fromJSON(value) : value;
186
+ return JSON.parse(response, reviver);
305
187
  }
306
188
  /**
307
189
  * Retrieves the content set size based on the supplied content descriptor override
308
190
  * @public
309
191
  */
310
192
  async getContentSetSize(requestOptions) {
311
- const { rulesetId, strippedOptions: { descriptor, ...strippedOptions } } = this.registerRuleset(requestOptions);
193
+ const { rulesetOrId, descriptor, ...strippedOptions } = requestOptions;
312
194
  const params = {
313
195
  requestId: NativePlatform_1.NativePlatformRequestTypes.GetContentSetSize,
314
- rulesetId,
196
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
315
197
  ...strippedOptions,
316
- keys: getKeysForContentRequest(requestOptions.keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
198
+ keys: (0, PresentationManagerDetail_1.getKeysForContentRequest)(requestOptions.keys, (map) => (0, PresentationManagerDetail_1.bisElementInstanceKeysProcessor)(requestOptions.imodel, map)),
317
199
  descriptorOverrides: createContentDescriptorOverrides(descriptor),
318
200
  };
319
- return this.request(params);
201
+ return JSON.parse(await this._detail.request(params));
320
202
  }
321
203
  /**
322
204
  * Retrieves the content based on the supplied content descriptor override.
323
205
  * @public
324
206
  */
325
207
  async getContent(requestOptions) {
326
- const { rulesetId, strippedOptions: { descriptor, ...strippedOptions } } = this.registerRuleset(requestOptions);
208
+ const { rulesetOrId, descriptor, ...strippedOptions } = requestOptions;
327
209
  const params = {
328
210
  requestId: NativePlatform_1.NativePlatformRequestTypes.GetContent,
329
- rulesetId,
211
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
330
212
  ...strippedOptions,
331
- keys: getKeysForContentRequest(requestOptions.keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
213
+ keys: (0, PresentationManagerDetail_1.getKeysForContentRequest)(requestOptions.keys, (map) => (0, PresentationManagerDetail_1.bisElementInstanceKeysProcessor)(requestOptions.imodel, map)),
332
214
  descriptorOverrides: createContentDescriptorOverrides(descriptor),
333
215
  };
334
- return this.request(params, presentation_common_1.Content.reviver);
216
+ return JSON.parse(await this._detail.request(params), presentation_common_1.Content.reviver);
335
217
  }
336
218
  /**
337
219
  * Retrieves distinct values of specific field from the content based on the supplied content descriptor override.
@@ -340,13 +222,13 @@ class PresentationManager {
340
222
  * @public
341
223
  */
342
224
  async getPagedDistinctValues(requestOptions) {
343
- const { rulesetId, strippedOptions } = this.registerRuleset(requestOptions);
225
+ const { rulesetOrId, ...strippedOptions } = requestOptions;
344
226
  const { descriptor, keys, ...strippedOptionsNoDescriptorAndKeys } = strippedOptions;
345
227
  const params = {
346
228
  requestId: NativePlatform_1.NativePlatformRequestTypes.GetPagedDistinctValues,
347
- rulesetId,
229
+ rulesetId: this._detail.registerRuleset(rulesetOrId),
348
230
  ...strippedOptionsNoDescriptorAndKeys,
349
- keys: getKeysForContentRequest(keys, (map) => bisElementInstanceKeysProcessor(requestOptions.imodel, map)),
231
+ keys: (0, PresentationManagerDetail_1.getKeysForContentRequest)(keys, (map) => (0, PresentationManagerDetail_1.bisElementInstanceKeysProcessor)(requestOptions.imodel, map)),
350
232
  descriptorOverrides: createContentDescriptorOverrides(descriptor),
351
233
  };
352
234
  const reviver = (key, value) => {
@@ -355,7 +237,7 @@ class PresentationManager {
355
237
  items: value.items.map(presentation_common_1.DisplayValueGroup.fromJSON),
356
238
  } : value;
357
239
  };
358
- return this.request(params, reviver);
240
+ return JSON.parse(await this._detail.request(params), reviver);
359
241
  }
360
242
  async getElementProperties(requestOptions) {
361
243
  if ((0, presentation_common_1.isSingleElementPropertiesRequestOptions)(requestOptions)) {
@@ -413,7 +295,7 @@ class PresentationManager {
413
295
  ...requestOptions,
414
296
  key: presentation_common_1.InstanceKey.toJSON(requestOptions.key),
415
297
  };
416
- return this.request(params, presentation_common_1.LabelDefinition.reviver);
298
+ return JSON.parse(await this._detail.request(params), presentation_common_1.LabelDefinition.reviver);
417
299
  }
418
300
  /**
419
301
  * Retrieves display label definitions of specific items
@@ -449,36 +331,13 @@ class PresentationManager {
449
331
  async getSelectionScopes(_requestOptions) {
450
332
  return SelectionScopesHelper_1.SelectionScopesHelper.getSelectionScopes();
451
333
  }
452
- /**
453
- * Computes selection set based on provided selection scope.
454
- * @public
455
- */
456
334
  async computeSelection(requestOptions) {
457
- const { ids, scopeId, ...opts } = requestOptions; // eslint-disable-line @typescript-eslint/no-unused-vars
458
- return SelectionScopesHelper_1.SelectionScopesHelper.computeSelection(opts, ids, scopeId);
459
- }
460
- async request(params, reviver) {
461
- const { requestId, imodel, locale, unitSystem, diagnostics, ...strippedParams } = params;
462
- if (this._onManagerUsed)
463
- this._onManagerUsed();
464
- const imodelAddon = this.getNativePlatform().getImodelAddon(imodel);
465
- const nativeRequestParams = {
466
- requestId,
467
- params: {
468
- locale: normalizeLocale(locale !== null && locale !== void 0 ? locale : this.activeLocale),
469
- unitSystem: toOptionalNativeUnitSystem(unitSystem !== null && unitSystem !== void 0 ? unitSystem : this.activeUnitSystem),
470
- ...strippedParams,
471
- },
472
- };
473
- let diagnosticsListener;
474
- if (diagnostics) {
475
- const { handler: tempDiagnosticsListener, ...diagnosticsOptions } = diagnostics;
476
- diagnosticsListener = tempDiagnosticsListener;
477
- nativeRequestParams.params.diagnostics = diagnosticsOptions;
478
- }
479
- const response = await this.getNativePlatform().handleRequest(imodelAddon, JSON.stringify(nativeRequestParams));
480
- diagnosticsListener && response.diagnostics && diagnosticsListener([response.diagnostics]);
481
- return JSON.parse(response.result, reviver);
335
+ return SelectionScopesHelper_1.SelectionScopesHelper.computeSelection((0, presentation_common_1.isComputeSelectionRequestOptions)(requestOptions)
336
+ ? requestOptions
337
+ : (function () {
338
+ const { ids, scopeId, ...rest } = requestOptions;
339
+ return { ...rest, elementIds: ids, scope: { id: scopeId } };
340
+ })());
482
341
  }
483
342
  /**
484
343
  * Compares two hierarchies specified in the request options
@@ -486,11 +345,13 @@ class PresentationManager {
486
345
  */
487
346
  async compareHierarchies(requestOptions) {
488
347
  var _a, _b;
489
- if (!requestOptions.prev.rulesetOrId && !requestOptions.prev.rulesetVariables)
348
+ if (!requestOptions.prev.rulesetOrId && !requestOptions.prev.rulesetVariables) {
490
349
  return { changes: [] };
491
- const { strippedOptions: { prev, rulesetVariables, ...options } } = this.registerRuleset(requestOptions);
492
- const currRulesetId = this.getRulesetIdObject(requestOptions.rulesetOrId);
493
- const prevRulesetId = prev.rulesetOrId ? this.getRulesetIdObject(prev.rulesetOrId) : currRulesetId;
350
+ }
351
+ const { rulesetOrId, prev, rulesetVariables, ...options } = requestOptions;
352
+ this._detail.registerRuleset(rulesetOrId);
353
+ const currRulesetId = (0, PresentationManagerDetail_1.getRulesetIdObject)(requestOptions.rulesetOrId);
354
+ const prevRulesetId = prev.rulesetOrId ? (0, PresentationManagerDetail_1.getRulesetIdObject)(prev.rulesetOrId) : currRulesetId;
494
355
  if (prevRulesetId.parts.id !== currRulesetId.parts.id)
495
356
  throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "Can't compare rulesets with different IDs");
496
357
  const currRulesetVariables = rulesetVariables !== null && rulesetVariables !== void 0 ? rulesetVariables : [];
@@ -504,134 +365,16 @@ class PresentationManager {
504
365
  currRulesetVariables: JSON.stringify(currRulesetVariables),
505
366
  expandedNodeKeys: JSON.stringify((_b = options.expandedNodeKeys) !== null && _b !== void 0 ? _b : []),
506
367
  };
507
- return this.request(params, (key, value) => ((key === "") ? presentation_common_1.HierarchyCompareInfo.fromJSON(value) : value));
368
+ const reviver = (key, value) => (key === "") ? presentation_common_1.HierarchyCompareInfo.fromJSON(value) : value;
369
+ return JSON.parse(await this._detail.request(params), reviver);
508
370
  }
509
371
  }
510
372
  exports.PresentationManager = PresentationManager;
511
- function addInstanceKey(classInstancesMap, key) {
512
- let set = classInstancesMap.get(key.className);
513
- // istanbul ignore else
514
- if (!set) {
515
- set = new Set();
516
- classInstancesMap.set(key.className, set);
517
- }
518
- set.add(key.id);
519
- }
520
- function bisElementInstanceKeysProcessor(imodel, classInstancesMap) {
521
- const elementClassName = "BisCore:Element";
522
- const elementIds = classInstancesMap.get(elementClassName);
523
- if (elementIds) {
524
- const deleteElementIds = new Array();
525
- elementIds.forEach((elementId) => {
526
- const concreteKey = (0, Utils_1.getElementKey)(imodel, elementId);
527
- if (concreteKey && concreteKey.className !== elementClassName) {
528
- deleteElementIds.push(elementId);
529
- addInstanceKey(classInstancesMap, { className: concreteKey.className, id: elementId });
530
- }
531
- });
532
- for (const id of deleteElementIds)
533
- elementIds.delete(id);
534
- }
535
- }
536
- /** @internal */
537
- function getKeysForContentRequest(keys, classInstanceKeysProcessor) {
538
- const result = {
539
- instanceKeys: [],
540
- nodeKeys: [],
541
- };
542
- const classInstancesMap = new Map();
543
- keys.forEach((key) => {
544
- if (presentation_common_1.Key.isNodeKey(key))
545
- result.nodeKeys.push(key);
546
- if (presentation_common_1.Key.isInstanceKey(key))
547
- addInstanceKey(classInstancesMap, key);
548
- });
549
- if (classInstanceKeysProcessor)
550
- classInstanceKeysProcessor(classInstancesMap);
551
- for (const entry of classInstancesMap) {
552
- if (entry[1].size > 0)
553
- result.instanceKeys.push([entry["0"], [...entry[1]]]);
554
- }
555
- return result;
556
- }
557
- exports.getKeysForContentRequest = getKeysForContentRequest;
558
373
  const createContentDescriptorOverrides = (descriptorOrOverrides) => {
559
374
  if (descriptorOrOverrides instanceof presentation_common_1.Descriptor)
560
375
  return descriptorOrOverrides.createDescriptorOverrides();
561
376
  return descriptorOrOverrides;
562
377
  };
563
- const createLocaleDirectoryList = (props) => {
564
- const localeDirectories = [(0, Utils_1.getLocalesDirectory)(getPresentationCommonAssetsRoot(props === null || props === void 0 ? void 0 : props.presentationAssetsRoot))];
565
- if (props && props.localeDirectories) {
566
- props.localeDirectories.forEach((dir) => {
567
- if (-1 === localeDirectories.indexOf(dir))
568
- localeDirectories.push(dir);
569
- });
570
- }
571
- return localeDirectories;
572
- };
573
- const createTaskAllocationsMap = (props) => {
574
- var _a;
575
- const count = (_a = props === null || props === void 0 ? void 0 : props.workerThreadsCount) !== null && _a !== void 0 ? _a : 2;
576
- return {
577
- [Number.MAX_SAFE_INTEGER]: count,
578
- };
579
- };
580
- const normalizeLocale = (locale) => {
581
- if (!locale)
582
- return undefined;
583
- return locale.toLocaleLowerCase();
584
- };
585
- const normalizeDirectory = (directory) => {
586
- return directory ? path.resolve(directory) : "";
587
- };
588
- const toNativeUnitSystem = (unitSystem) => {
589
- switch (unitSystem) {
590
- case "imperial": return NativePlatform_1.NativePresentationUnitSystem.BritishImperial;
591
- case "metric": return NativePlatform_1.NativePresentationUnitSystem.Metric;
592
- case "usCustomary": return NativePlatform_1.NativePresentationUnitSystem.UsCustomary;
593
- case "usSurvey": return NativePlatform_1.NativePresentationUnitSystem.UsSurvey;
594
- }
595
- };
596
- const toOptionalNativeUnitSystem = (unitSystem) => {
597
- return unitSystem ? toNativeUnitSystem(unitSystem) : undefined;
598
- };
599
- const toNativeUnitFormatsMap = (map) => {
600
- if (!map)
601
- return undefined;
602
- const nativeFormatsMap = {};
603
- Object.keys(map).forEach((phenomenon) => {
604
- const unitSystemsFormat = map[phenomenon];
605
- nativeFormatsMap[phenomenon] = {
606
- unitSystems: unitSystemsFormat.unitSystems.map(toNativeUnitSystem),
607
- format: unitSystemsFormat.format,
608
- };
609
- });
610
- return nativeFormatsMap;
611
- };
612
- const createCacheConfig = (config) => {
613
- if ((config === null || config === void 0 ? void 0 : config.mode) === HierarchyCacheMode.Disk)
614
- return { ...config, directory: normalizeDirectory(config.directory) };
615
- if ((config === null || config === void 0 ? void 0 : config.mode) === HierarchyCacheMode.Hybrid)
616
- return { ...config, disk: config.disk ? { ...config.disk, directory: normalizeDirectory(config.disk.directory) } : undefined };
617
- if ((config === null || config === void 0 ? void 0 : config.mode) === HierarchyCacheMode.Memory)
618
- return config;
619
- return { mode: HierarchyCacheMode.Disk, directory: "" };
620
- };
621
- const getPresentationBackendAssetsRoot = (ovr) => {
622
- if (typeof ovr === "string")
623
- return ovr;
624
- if (typeof ovr === "object")
625
- return ovr.backend;
626
- return Constants_1.PRESENTATION_BACKEND_ASSETS_ROOT;
627
- };
628
- const getPresentationCommonAssetsRoot = (ovr) => {
629
- if (typeof ovr === "string")
630
- return ovr;
631
- if (typeof ovr === "object")
632
- return ovr.common;
633
- return Constants_1.PRESENTATION_COMMON_ASSETS_ROOT;
634
- };
635
378
  const ELEMENT_PROPERTIES_CONTENT_BATCH_SIZE = 100;
636
379
  async function buildElementsPropertiesInPages(className, ids, getter) {
637
380
  const elementProperties = [];