@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,86 @@
1
+ /** @packageDocumentation
2
+ * @module Core
3
+ */
4
+ import { IModelDb, IModelJsNative } from "@itwin/core-backend";
5
+ import { IDisposable } from "@itwin/core-bentley";
6
+ import { FormatProps } from "@itwin/core-quantity";
7
+ import { DiagnosticsScopeLogs, NodeKeyJSON, UpdateInfoJSON, VariableValue, VariableValueTypes } from "@itwin/presentation-common";
8
+ import { PresentationManagerMode } from "./PresentationManager";
9
+ /** @internal */
10
+ export declare enum NativePlatformRequestTypes {
11
+ GetRootNodes = "GetRootNodes",
12
+ GetRootNodesCount = "GetRootNodesCount",
13
+ GetChildren = "GetChildren",
14
+ GetChildrenCount = "GetChildrenCount",
15
+ GetNodePaths = "GetNodePaths",
16
+ GetFilteredNodePaths = "GetFilteredNodePaths",
17
+ GetContentSources = "GetContentSources",
18
+ GetContentDescriptor = "GetContentDescriptor",
19
+ GetContentSetSize = "GetContentSetSize",
20
+ GetContent = "GetContent",
21
+ GetDistinctValues = "GetDistinctValues",
22
+ GetPagedDistinctValues = "GetPagedDistinctValues",
23
+ GetDisplayLabel = "GetDisplayLabel",
24
+ CompareHierarchies = "CompareHierarchies"
25
+ }
26
+ /**
27
+ * Enumeration of unit systems supported by native presentation manager.
28
+ * @internal
29
+ */
30
+ export declare enum NativePresentationUnitSystem {
31
+ Metric = "metric",
32
+ BritishImperial = "british-imperial",
33
+ UsCustomary = "us-customary",
34
+ UsSurvey = "us-survey"
35
+ }
36
+ /** @internal */
37
+ export interface NativePresentationDefaultUnitFormats {
38
+ [phenomenon: string]: {
39
+ unitSystems: NativePresentationUnitSystem[];
40
+ format: FormatProps;
41
+ };
42
+ }
43
+ /** @internal */
44
+ export interface NativePresentationKeySetJSON {
45
+ instanceKeys: Array<[string, string[]]>;
46
+ nodeKeys: NodeKeyJSON[];
47
+ }
48
+ /** @internal */
49
+ export interface NativePlatformResponse<TResult> {
50
+ result: TResult;
51
+ diagnostics?: DiagnosticsScopeLogs;
52
+ }
53
+ /** @internal */
54
+ export interface NativePlatformDefinition extends IDisposable {
55
+ getImodelAddon(imodel: IModelDb): any;
56
+ setupRulesetDirectories(directories: string[]): NativePlatformResponse<void>;
57
+ setupSupplementalRulesetDirectories(directories: string[]): NativePlatformResponse<void>;
58
+ forceLoadSchemas(db: any): Promise<NativePlatformResponse<void>>;
59
+ getRulesets(rulesetId: string): NativePlatformResponse<string>;
60
+ addRuleset(serializedRulesetJson: string): NativePlatformResponse<string>;
61
+ removeRuleset(rulesetId: string, hash: string): NativePlatformResponse<boolean>;
62
+ clearRulesets(): NativePlatformResponse<void>;
63
+ handleRequest(db: any, options: string): Promise<NativePlatformResponse<string>>;
64
+ getRulesetVariableValue(rulesetId: string, variableId: string, type: VariableValueTypes): NativePlatformResponse<VariableValue>;
65
+ setRulesetVariableValue(rulesetId: string, variableId: string, type: VariableValueTypes, value: VariableValue): NativePlatformResponse<void>;
66
+ unsetRulesetVariableValue(rulesetId: string, variableId: string): NativePlatformResponse<void>;
67
+ getUpdateInfo(): NativePlatformResponse<UpdateInfoJSON | undefined>;
68
+ updateHierarchyState(db: any, rulesetId: string, changeType: "nodesExpanded" | "nodesCollapsed", serializedKeys: string): NativePlatformResponse<void>;
69
+ }
70
+ /** @internal */
71
+ export interface DefaultNativePlatformProps {
72
+ id: string;
73
+ localeDirectories: string[];
74
+ taskAllocationsMap: {
75
+ [priority: number]: number;
76
+ };
77
+ mode: PresentationManagerMode;
78
+ isChangeTrackingEnabled: boolean;
79
+ cacheConfig?: IModelJsNative.ECPresentationHierarchyCacheConfig;
80
+ contentCacheSize?: number;
81
+ defaultFormats?: NativePresentationDefaultUnitFormats;
82
+ useMmap?: boolean | number;
83
+ }
84
+ /** @internal */
85
+ export declare const createDefaultNativePlatform: (props: DefaultNativePlatformProps) => new () => NativePlatformDefinition;
86
+ //# sourceMappingURL=NativePlatform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativePlatform.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/NativePlatform.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAc,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,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EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,GAAG,gBAAgB,EAAE,cAAc,EAAE,MAAM,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;CACxJ;AAED,gBAAgB;AAChB,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,kBAAkB,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACnD,IAAI,EAAE,uBAAuB,CAAC;IAC9B,uBAAuB,EAAE,OAAO,CAAC;IACjC,WAAW,CAAC,EAAE,cAAc,CAAC,kCAAkC,CAAC;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,oCAAoC,CAAC;IACtD,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC5B;AAED,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,UAAW,0BAA0B,KAAG,UAAU,wBAiHzF,CAAC"}
@@ -0,0 +1,153 @@
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.createDefaultNativePlatform = exports.NativePresentationUnitSystem = exports.NativePlatformRequestTypes = void 0;
11
+ const core_backend_1 = require("@itwin/core-backend");
12
+ const presentation_common_1 = require("@itwin/presentation-common");
13
+ const PresentationManager_1 = require("./PresentationManager");
14
+ /** @internal */
15
+ var NativePlatformRequestTypes;
16
+ (function (NativePlatformRequestTypes) {
17
+ NativePlatformRequestTypes["GetRootNodes"] = "GetRootNodes";
18
+ NativePlatformRequestTypes["GetRootNodesCount"] = "GetRootNodesCount";
19
+ NativePlatformRequestTypes["GetChildren"] = "GetChildren";
20
+ NativePlatformRequestTypes["GetChildrenCount"] = "GetChildrenCount";
21
+ NativePlatformRequestTypes["GetNodePaths"] = "GetNodePaths";
22
+ NativePlatformRequestTypes["GetFilteredNodePaths"] = "GetFilteredNodePaths";
23
+ NativePlatformRequestTypes["GetContentSources"] = "GetContentSources";
24
+ NativePlatformRequestTypes["GetContentDescriptor"] = "GetContentDescriptor";
25
+ NativePlatformRequestTypes["GetContentSetSize"] = "GetContentSetSize";
26
+ NativePlatformRequestTypes["GetContent"] = "GetContent";
27
+ NativePlatformRequestTypes["GetDistinctValues"] = "GetDistinctValues";
28
+ NativePlatformRequestTypes["GetPagedDistinctValues"] = "GetPagedDistinctValues";
29
+ NativePlatformRequestTypes["GetDisplayLabel"] = "GetDisplayLabel";
30
+ NativePlatformRequestTypes["CompareHierarchies"] = "CompareHierarchies";
31
+ })(NativePlatformRequestTypes = exports.NativePlatformRequestTypes || (exports.NativePlatformRequestTypes = {}));
32
+ /**
33
+ * Enumeration of unit systems supported by native presentation manager.
34
+ * @internal
35
+ */
36
+ var NativePresentationUnitSystem;
37
+ (function (NativePresentationUnitSystem) {
38
+ NativePresentationUnitSystem["Metric"] = "metric";
39
+ NativePresentationUnitSystem["BritishImperial"] = "british-imperial";
40
+ NativePresentationUnitSystem["UsCustomary"] = "us-customary";
41
+ NativePresentationUnitSystem["UsSurvey"] = "us-survey";
42
+ })(NativePresentationUnitSystem = exports.NativePresentationUnitSystem || (exports.NativePresentationUnitSystem = {}));
43
+ /** @internal */
44
+ const createDefaultNativePlatform = (props) => {
45
+ // note the implementation is constructed here to make PresentationManager
46
+ // usable without loading the actual addon (if addon is set to something other)
47
+ return class {
48
+ constructor() {
49
+ var _a;
50
+ const mode = (props.mode === PresentationManager_1.PresentationManagerMode.ReadOnly) ? "ro" /* ReadOnly */ : "rw" /* ReadWrite */;
51
+ const cacheConfig = (_a = props.cacheConfig) !== null && _a !== void 0 ? _a : { mode: PresentationManager_1.HierarchyCacheMode.Disk, directory: "" };
52
+ const defaultFormats = props.defaultFormats ? this.getSerializedDefaultFormatsMap(props.defaultFormats) : {};
53
+ this._nativeAddon = new core_backend_1.IModelHost.platform.ECPresentationManager({ ...props, mode, cacheConfig, defaultFormats });
54
+ }
55
+ getStatus(responseStatus) {
56
+ switch (responseStatus) {
57
+ case 65537 /* InvalidArgument */: return presentation_common_1.PresentationStatus.InvalidArgument;
58
+ case 1 /* Canceled */: return presentation_common_1.PresentationStatus.Canceled;
59
+ default: return presentation_common_1.PresentationStatus.Error;
60
+ }
61
+ }
62
+ getSerializedDefaultFormatsMap(defaultMap) {
63
+ const res = {};
64
+ Object.keys(defaultMap).forEach((key) => {
65
+ const value = defaultMap[key];
66
+ res[key] = { unitSystems: value.unitSystems, serializedFormat: JSON.stringify(value.format) };
67
+ });
68
+ return res;
69
+ }
70
+ createSuccessResponse(response) {
71
+ const retValue = { result: response.result };
72
+ if (response.diagnostics)
73
+ retValue.diagnostics = response.diagnostics;
74
+ return retValue;
75
+ }
76
+ handleResult(response) {
77
+ if (response.error)
78
+ throw new presentation_common_1.PresentationError(this.getStatus(response.error.status), response.error.message);
79
+ return this.createSuccessResponse(response);
80
+ }
81
+ handleVoidResult(response) {
82
+ if (response.error)
83
+ throw new presentation_common_1.PresentationError(this.getStatus(response.error.status), response.error.message);
84
+ return this.createSuccessResponse(response);
85
+ }
86
+ dispose() {
87
+ this._nativeAddon.dispose();
88
+ }
89
+ async forceLoadSchemas(db) {
90
+ const response = await this._nativeAddon.forceLoadSchemas(db);
91
+ if (response.error)
92
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, response.error.message);
93
+ return this.createSuccessResponse(response);
94
+ }
95
+ setupRulesetDirectories(directories) {
96
+ return this.handleVoidResult(this._nativeAddon.setupRulesetDirectories(directories));
97
+ }
98
+ setupSupplementalRulesetDirectories(directories) {
99
+ return this.handleVoidResult(this._nativeAddon.setupSupplementalRulesetDirectories(directories));
100
+ }
101
+ getImodelAddon(imodel) {
102
+ if (!imodel.nativeDb)
103
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "imodel");
104
+ return imodel.nativeDb;
105
+ }
106
+ getRulesets(rulesetId) {
107
+ return this.handleResult(this._nativeAddon.getRulesets(rulesetId));
108
+ }
109
+ addRuleset(serializedRulesetJson) {
110
+ return this.handleResult(this._nativeAddon.addRuleset(serializedRulesetJson));
111
+ }
112
+ removeRuleset(rulesetId, hash) {
113
+ return this.handleResult(this._nativeAddon.removeRuleset(rulesetId, hash));
114
+ }
115
+ clearRulesets() {
116
+ return this.handleVoidResult(this._nativeAddon.clearRulesets());
117
+ }
118
+ async handleRequest(db, options) {
119
+ const requestGuid = this.handleResult(this._nativeAddon.queueRequest(db, options)).result;
120
+ return new Promise((resolve, reject) => {
121
+ const interval = setInterval(() => {
122
+ const pollResult = this._nativeAddon.pollResponse(requestGuid);
123
+ if (pollResult.error) {
124
+ if (pollResult.error.status !== 2 /* Pending */) {
125
+ reject(new presentation_common_1.PresentationError(this.getStatus(pollResult.error.status), pollResult.error.message));
126
+ clearInterval(interval);
127
+ }
128
+ return; // ignore 'pending' responses
129
+ }
130
+ resolve(this.createSuccessResponse(pollResult));
131
+ clearInterval(interval);
132
+ }, 20);
133
+ });
134
+ }
135
+ getRulesetVariableValue(rulesetId, variableId, type) {
136
+ return this.handleResult(this._nativeAddon.getRulesetVariableValue(rulesetId, variableId, type));
137
+ }
138
+ setRulesetVariableValue(rulesetId, variableId, type, value) {
139
+ return this.handleVoidResult(this._nativeAddon.setRulesetVariableValue(rulesetId, variableId, type, value));
140
+ }
141
+ unsetRulesetVariableValue(rulesetId, variableId) {
142
+ return this.handleVoidResult(this._nativeAddon.unsetRulesetVariableValue(rulesetId, variableId));
143
+ }
144
+ getUpdateInfo() {
145
+ return this.handleResult(this._nativeAddon.getUpdateInfo());
146
+ }
147
+ updateHierarchyState(db, rulesetId, changeType, serializedKeys) {
148
+ return this.handleResult(this._nativeAddon.updateHierarchyState(db, rulesetId, changeType, serializedKeys));
149
+ }
150
+ };
151
+ };
152
+ exports.createDefaultNativePlatform = createDefaultNativePlatform;
153
+ //# sourceMappingURL=NativePlatform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativePlatform.js","sourceRoot":"","sources":["../../../src/presentation-backend/NativePlatform.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2E;AAG3E,oEAEoC;AACpC,+DAAoF;AAEpF,gBAAgB;AAChB,IAAY,0BAeX;AAfD,WAAY,0BAA0B;IACpC,2DAA6B,CAAA;IAC7B,qEAAuC,CAAA;IACvC,yDAA2B,CAAA;IAC3B,mEAAqC,CAAA;IACrC,2DAA6B,CAAA;IAC7B,2EAA6C,CAAA;IAC7C,qEAAuC,CAAA;IACvC,2EAA6C,CAAA;IAC7C,qEAAuC,CAAA;IACvC,uDAAyB,CAAA;IACzB,qEAAuC,CAAA;IACvC,+EAAiD,CAAA;IACjD,iEAAmC,CAAA;IACnC,uEAAyC,CAAA;AAC3C,CAAC,EAfW,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAerC;AAED;;;GAGG;AACH,IAAY,4BAKX;AALD,WAAY,4BAA4B;IACtC,iDAAiB,CAAA;IACjB,oEAAoC,CAAA;IACpC,4DAA4B,CAAA;IAC5B,sDAAsB,CAAA;AACxB,CAAC,EALW,4BAA4B,GAA5B,oCAA4B,KAA5B,oCAA4B,QAKvC;AA2DD,gBAAgB;AACT,MAAM,2BAA2B,GAAG,CAAC,KAAiC,EAAsC,EAAE;IACnH,0EAA0E;IAC1E,+EAA+E;IAC/E,OAAO;QAEL;;YACE,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,6CAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,qBAAmD,CAAC,qBAAmD,CAAC;YACxK,MAAM,WAAW,GAAG,MAAA,KAAK,CAAC,WAAW,mCAAI,EAAE,IAAI,EAAE,wCAAkB,CAAC,IAAI,EAA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AE,cAAc,CAAC,CAAC,CAAC;QAC9G,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAjHW,QAAA,2BAA2B,+BAiHtC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { IModelDb, IModelHost, IModelJsNative } from \"@itwin/core-backend\";\r\nimport { IDisposable } from \"@itwin/core-bentley\";\r\nimport { FormatProps } from \"@itwin/core-quantity\";\r\nimport {\r\n DiagnosticsScopeLogs, NodeKeyJSON, PresentationError, PresentationStatus, UpdateInfoJSON, VariableValue, VariableValueJSON, VariableValueTypes,\r\n} from \"@itwin/presentation-common\";\r\nimport { HierarchyCacheMode, PresentationManagerMode } from \"./PresentationManager\";\r\n\r\n/** @internal */\r\nexport enum NativePlatformRequestTypes {\r\n GetRootNodes = \"GetRootNodes\",\r\n GetRootNodesCount = \"GetRootNodesCount\",\r\n GetChildren = \"GetChildren\",\r\n GetChildrenCount = \"GetChildrenCount\",\r\n GetNodePaths = \"GetNodePaths\",\r\n GetFilteredNodePaths = \"GetFilteredNodePaths\",\r\n GetContentSources = \"GetContentSources\",\r\n GetContentDescriptor = \"GetContentDescriptor\",\r\n GetContentSetSize = \"GetContentSetSize\",\r\n GetContent = \"GetContent\",\r\n GetDistinctValues = \"GetDistinctValues\",\r\n GetPagedDistinctValues = \"GetPagedDistinctValues\",\r\n GetDisplayLabel = \"GetDisplayLabel\",\r\n CompareHierarchies = \"CompareHierarchies\",\r\n}\r\n\r\n/**\r\n * Enumeration of unit systems supported by native presentation manager.\r\n * @internal\r\n */\r\nexport enum NativePresentationUnitSystem {\r\n Metric = \"metric\",\r\n BritishImperial = \"british-imperial\",\r\n UsCustomary = \"us-customary\",\r\n UsSurvey = \"us-survey\",\r\n}\r\n\r\n/** @internal */\r\nexport interface NativePresentationDefaultUnitFormats {\r\n [phenomenon: string]: {\r\n unitSystems: NativePresentationUnitSystem[];\r\n format: FormatProps;\r\n };\r\n}\r\n\r\n/** @internal */\r\nexport interface NativePresentationKeySetJSON {\r\n instanceKeys: Array<[string, string[]]>;\r\n nodeKeys: NodeKeyJSON[];\r\n}\r\n\r\n/** @internal */\r\nexport interface NativePlatformResponse<TResult> {\r\n result: TResult;\r\n diagnostics?: DiagnosticsScopeLogs;\r\n}\r\n\r\n/** @internal */\r\nexport interface NativePlatformDefinition extends IDisposable {\r\n getImodelAddon(imodel: IModelDb): any;\r\n\r\n setupRulesetDirectories(directories: string[]): NativePlatformResponse<void>;\r\n setupSupplementalRulesetDirectories(directories: string[]): NativePlatformResponse<void>;\r\n\r\n forceLoadSchemas(db: any): Promise<NativePlatformResponse<void>>;\r\n\r\n getRulesets(rulesetId: string): NativePlatformResponse<string>;\r\n addRuleset(serializedRulesetJson: string): NativePlatformResponse<string>;\r\n removeRuleset(rulesetId: string, hash: string): NativePlatformResponse<boolean>;\r\n clearRulesets(): NativePlatformResponse<void>;\r\n\r\n handleRequest(db: any, options: string): Promise<NativePlatformResponse<string>>;\r\n\r\n getRulesetVariableValue(rulesetId: string, variableId: string, type: VariableValueTypes): NativePlatformResponse<VariableValue>;\r\n setRulesetVariableValue(rulesetId: string, variableId: string, type: VariableValueTypes, value: VariableValue): NativePlatformResponse<void>;\r\n unsetRulesetVariableValue(rulesetId: string, variableId: string): NativePlatformResponse<void>;\r\n\r\n getUpdateInfo(): NativePlatformResponse<UpdateInfoJSON | undefined>;\r\n updateHierarchyState(db: any, rulesetId: string, changeType: \"nodesExpanded\" | \"nodesCollapsed\", serializedKeys: string): NativePlatformResponse<void>;\r\n}\r\n\r\n/** @internal */\r\nexport interface DefaultNativePlatformProps {\r\n id: string;\r\n localeDirectories: string[];\r\n taskAllocationsMap: { [priority: number]: number };\r\n mode: PresentationManagerMode;\r\n isChangeTrackingEnabled: boolean;\r\n cacheConfig?: IModelJsNative.ECPresentationHierarchyCacheConfig;\r\n contentCacheSize?: number;\r\n defaultFormats?: NativePresentationDefaultUnitFormats;\r\n useMmap?: boolean | number;\r\n}\r\n\r\n/** @internal */\r\nexport const createDefaultNativePlatform = (props: DefaultNativePlatformProps): new () => NativePlatformDefinition => {\r\n // note the implementation is constructed here to make PresentationManager\r\n // usable without loading the actual addon (if addon is set to something other)\r\n return class implements NativePlatformDefinition {\r\n private _nativeAddon: IModelJsNative.ECPresentationManager;\r\n public constructor() {\r\n const mode = (props.mode === PresentationManagerMode.ReadOnly) ? IModelJsNative.ECPresentationManagerMode.ReadOnly : IModelJsNative.ECPresentationManagerMode.ReadWrite;\r\n const cacheConfig = props.cacheConfig ?? { mode: HierarchyCacheMode.Disk, directory: \"\" };\r\n const defaultFormats = props.defaultFormats ? this.getSerializedDefaultFormatsMap(props.defaultFormats) : {};\r\n this._nativeAddon = new IModelHost.platform.ECPresentationManager({ ...props, mode, cacheConfig, defaultFormats });\r\n }\r\n private getStatus(responseStatus: IModelJsNative.ECPresentationStatus): PresentationStatus {\r\n switch (responseStatus) {\r\n case IModelJsNative.ECPresentationStatus.InvalidArgument: return PresentationStatus.InvalidArgument;\r\n case IModelJsNative.ECPresentationStatus.Canceled: return PresentationStatus.Canceled;\r\n default: return PresentationStatus.Error;\r\n }\r\n }\r\n private getSerializedDefaultFormatsMap(defaultMap: NativePresentationDefaultUnitFormats) {\r\n const res: {\r\n [phenomenon: string]: {\r\n unitSystems: string[];\r\n serializedFormat: string;\r\n };\r\n } = {};\r\n Object.keys(defaultMap).forEach((key) => {\r\n const value = defaultMap[key];\r\n res[key] = { unitSystems: value.unitSystems, serializedFormat: JSON.stringify(value.format) };\r\n });\r\n\r\n return res;\r\n }\r\n private createSuccessResponse<T>(response: IModelJsNative.ECPresentationManagerResponse<T>): NativePlatformResponse<T> {\r\n const retValue: NativePlatformResponse<T> = { result: response.result! };\r\n if (response.diagnostics)\r\n retValue.diagnostics = response.diagnostics;\r\n return retValue;\r\n }\r\n private handleResult<T>(response: IModelJsNative.ECPresentationManagerResponse<T>): NativePlatformResponse<T> {\r\n if (response.error)\r\n throw new PresentationError(this.getStatus(response.error.status), response.error.message);\r\n return this.createSuccessResponse(response);\r\n }\r\n private handleVoidResult(response: IModelJsNative.ECPresentationManagerResponse<void>): NativePlatformResponse<void> {\r\n if (response.error)\r\n throw new PresentationError(this.getStatus(response.error.status), response.error.message);\r\n return this.createSuccessResponse(response);\r\n }\r\n public dispose() {\r\n this._nativeAddon.dispose();\r\n }\r\n public async forceLoadSchemas(db: any): Promise<NativePlatformResponse<void>> {\r\n const response = await this._nativeAddon.forceLoadSchemas(db);\r\n if (response.error)\r\n throw new PresentationError(PresentationStatus.Error, response.error.message);\r\n return this.createSuccessResponse(response);\r\n }\r\n public setupRulesetDirectories(directories: string[]) {\r\n return this.handleVoidResult(this._nativeAddon.setupRulesetDirectories(directories));\r\n }\r\n public setupSupplementalRulesetDirectories(directories: string[]) {\r\n return this.handleVoidResult(this._nativeAddon.setupSupplementalRulesetDirectories(directories));\r\n }\r\n public getImodelAddon(imodel: IModelDb): any {\r\n if (!imodel.nativeDb)\r\n throw new PresentationError(PresentationStatus.InvalidArgument, \"imodel\");\r\n return imodel.nativeDb;\r\n }\r\n public getRulesets(rulesetId: string) {\r\n return this.handleResult(this._nativeAddon.getRulesets(rulesetId));\r\n }\r\n public addRuleset(serializedRulesetJson: string) {\r\n return this.handleResult(this._nativeAddon.addRuleset(serializedRulesetJson));\r\n }\r\n public removeRuleset(rulesetId: string, hash: string) {\r\n return this.handleResult(this._nativeAddon.removeRuleset(rulesetId, hash));\r\n }\r\n public clearRulesets() {\r\n return this.handleVoidResult(this._nativeAddon.clearRulesets());\r\n }\r\n public async handleRequest(db: any, options: string) {\r\n const requestGuid = this.handleResult(this._nativeAddon.queueRequest(db, options)).result;\r\n return new Promise((resolve: (result: NativePlatformResponse<any>) => void, reject) => {\r\n const interval = setInterval(() => {\r\n const pollResult = this._nativeAddon.pollResponse(requestGuid);\r\n if (pollResult.error) {\r\n if (pollResult.error.status !== IModelJsNative.ECPresentationStatus.Pending) {\r\n reject(new PresentationError(this.getStatus(pollResult.error.status), pollResult.error.message));\r\n clearInterval(interval);\r\n }\r\n return; // ignore 'pending' responses\r\n }\r\n resolve(this.createSuccessResponse(pollResult));\r\n clearInterval(interval);\r\n }, 20);\r\n });\r\n }\r\n public getRulesetVariableValue(rulesetId: string, variableId: string, type: VariableValueTypes) {\r\n return this.handleResult(this._nativeAddon.getRulesetVariableValue(rulesetId, variableId, type));\r\n }\r\n public setRulesetVariableValue(rulesetId: string, variableId: string, type: VariableValueTypes, value: VariableValueJSON) {\r\n return this.handleVoidResult(this._nativeAddon.setRulesetVariableValue(rulesetId, variableId, type, value));\r\n }\r\n public unsetRulesetVariableValue(rulesetId: string, variableId: string) {\r\n return this.handleVoidResult(this._nativeAddon.unsetRulesetVariableValue(rulesetId, variableId));\r\n }\r\n public getUpdateInfo() {\r\n return this.handleResult(this._nativeAddon.getUpdateInfo());\r\n }\r\n public updateHierarchyState(db: any, rulesetId: string, changeType: \"nodesExpanded\" | \"nodesCollapsed\", serializedKeys: string) {\r\n return this.handleResult(this._nativeAddon.updateHierarchyState(db, rulesetId, changeType, serializedKeys));\r\n }\r\n };\r\n};\r\n"]}
@@ -0,0 +1,98 @@
1
+ /** @packageDocumentation
2
+ * @module Core
3
+ */
4
+ import { PresentationManager, PresentationManagerProps } from "./PresentationManager";
5
+ /**
6
+ * Props for initializing the [[Presentation]] library for using multiple [[PresentationManager]]
7
+ * instances, one for each frontend.
8
+ *
9
+ * @public
10
+ */
11
+ export interface MultiManagerPresentationProps extends PresentationManagerProps {
12
+ /**
13
+ * Factory method for creating separate managers for each client
14
+ * @internal
15
+ */
16
+ clientManagerFactory?: (clientId: string, props: PresentationManagerProps) => PresentationManager;
17
+ /**
18
+ * Time in milliseconds after which the request will timeout.
19
+ */
20
+ requestTimeout?: number;
21
+ /**
22
+ * How much time should an unused client manager be stored in memory
23
+ * before it's disposed.
24
+ */
25
+ unusedClientLifetime?: number;
26
+ }
27
+ /**
28
+ * Props for initializing the [[Presentation]] library with ability to use a single
29
+ * [[PresentationManager]] instance for handling all requests.
30
+ *
31
+ * @public
32
+ */
33
+ export interface SingleManagerPresentationProps extends PresentationManagerProps {
34
+ /**
35
+ * How much time should an unused client manager be stored in memory
36
+ * before it's disposed.
37
+ */
38
+ requestTimeout?: number;
39
+ /**
40
+ * Specifies to use single manager for all clients.
41
+ * @alpha
42
+ */
43
+ useSingleManager?: boolean;
44
+ }
45
+ /**
46
+ * Properties that can be used to configure [[Presentation]] API
47
+ * @public
48
+ */
49
+ export declare type PresentationProps = MultiManagerPresentationProps | SingleManagerPresentationProps;
50
+ /**
51
+ * Static class used to statically set up Presentation library for the backend.
52
+ * Basically what it does is:
53
+ * - Register a RPC implementation
54
+ * - Create a singleton [[PresentationManager]] instance
55
+ * - Subscribe for [IModelHost.onBeforeShutdown]($core-backend) event and terminate
56
+ * the presentation manager when that happens.
57
+ *
58
+ * @public
59
+ */
60
+ export declare class Presentation {
61
+ private static _initProps;
62
+ private static _clientsStorage;
63
+ private static _requestTimeout;
64
+ private static _disposeIpcHandler;
65
+ private static _shutdownListener;
66
+ private static _manager;
67
+ private constructor();
68
+ /** Properties used to initialize the presentation framework */
69
+ static get initProps(): PresentationProps | undefined;
70
+ /**
71
+ * Initializes Presentation library for the backend.
72
+ *
73
+ * See [this]($docs/presentation/Setup/index.md#backend) for an example.
74
+ *
75
+ * **Important:** The method should be called after a call to [IModelHost.startup]($core-backend)
76
+ *
77
+ * @param props Optional properties for [[PresentationManager]]
78
+ */
79
+ static initialize(props?: PresentationProps): void;
80
+ /**
81
+ * Terminates Presentation. Consumers don't need to call this as it's automatically
82
+ * called on [IModelHost.onBeforeShutdown]($core-backend) event.
83
+ */
84
+ static terminate(): void;
85
+ private static createClientManager;
86
+ private static disposeClientManager;
87
+ /**
88
+ * Get an instance of [[PresentationManager]] for specific client
89
+ * @param clientId ID of the client requesting presentation data. If no
90
+ * ID is provided, the default [[PresentationManager]] is returned.
91
+ */
92
+ static getManager(clientId?: string): PresentationManager;
93
+ /**
94
+ * Get the time in milliseconds that backend should respond in .
95
+ */
96
+ static getRequestTimeout(): number;
97
+ }
98
+ //# sourceMappingURL=Presentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Presentation.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/Presentation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAQH,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAMtF;;;;;GAKG;AACH,MAAM,WAAW,6BAA8B,SAAQ,wBAAwB;IAC7E;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB,KAAK,mBAAmB,CAAC;IAElG;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,8BAA+B,SAAQ,wBAAwB;IAC9E;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;GAGG;AACH,oBAAY,iBAAiB,GAAG,6BAA6B,GAAG,8BAA8B,CAAC;AAM/F;;;;;;;;;GASG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAgC;IACzD,OAAO,CAAC,MAAM,CAAC,eAAe,CAAgD;IAC9E,OAAO,CAAC,MAAM,CAAC,eAAe,CAAqB;IACnD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA0B;IAC3D,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA0B;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkC;IAGzD,OAAO;IAEP,+DAA+D;IAC/D,WAAkB,SAAS,kCAA8B;IAEzD;;;;;;;;OAQG;WACW,UAAU,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,IAAI;IA6BzD;;;OAGG;WACW,SAAS,IAAI,IAAI;IAsB/B,OAAO,CAAC,MAAM,CAAC,mBAAmB;IASlC,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAInC;;;;OAIG;WACW,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,mBAAmB;IAShE;;OAEG;WACW,iBAAiB,IAAI,MAAM;CAK1C"}
@@ -0,0 +1,135 @@
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.Presentation = void 0;
11
+ const core_backend_1 = require("@itwin/core-backend");
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const presentation_common_1 = require("@itwin/presentation-common");
15
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
16
+ const PresentationIpcHandler_1 = require("./PresentationIpcHandler");
17
+ const PresentationManager_1 = require("./PresentationManager");
18
+ const PresentationRpcImpl_1 = require("./PresentationRpcImpl");
19
+ const TemporaryStorage_1 = require("./TemporaryStorage");
20
+ const defaultRequestTimeout = 90000;
21
+ /**
22
+ * Static class used to statically set up Presentation library for the backend.
23
+ * Basically what it does is:
24
+ * - Register a RPC implementation
25
+ * - Create a singleton [[PresentationManager]] instance
26
+ * - Subscribe for [IModelHost.onBeforeShutdown]($core-backend) event and terminate
27
+ * the presentation manager when that happens.
28
+ *
29
+ * @public
30
+ */
31
+ class Presentation {
32
+ /* istanbul ignore next */
33
+ constructor() { }
34
+ /** Properties used to initialize the presentation framework */
35
+ static get initProps() { return this._initProps; }
36
+ /**
37
+ * Initializes Presentation library for the backend.
38
+ *
39
+ * See [this]($docs/presentation/Setup/index.md#backend) for an example.
40
+ *
41
+ * **Important:** The method should be called after a call to [IModelHost.startup]($core-backend)
42
+ *
43
+ * @param props Optional properties for [[PresentationManager]]
44
+ */
45
+ static initialize(props) {
46
+ var _a;
47
+ core_common_1.RpcManager.registerImpl(presentation_common_1.PresentationRpcInterface, PresentationRpcImpl_1.PresentationRpcImpl);
48
+ if (core_backend_1.IpcHost.isValid) {
49
+ this._disposeIpcHandler = PresentationIpcHandler_1.PresentationIpcHandler.register();
50
+ }
51
+ this._initProps = props || {};
52
+ this._shutdownListener = core_backend_1.IModelHost.onBeforeShutdown.addListener(() => Presentation.terminate());
53
+ this._requestTimeout = (props && props.requestTimeout !== undefined)
54
+ ? props.requestTimeout
55
+ : defaultRequestTimeout;
56
+ if (isSingleManagerProps(this._initProps)) {
57
+ this._manager = new PresentationManager_1.PresentationManager(Presentation._initProps);
58
+ }
59
+ else {
60
+ this._clientsStorage = new TemporaryStorage_1.TemporaryStorage({
61
+ factory: this.createClientManager,
62
+ cleanupHandler: this.disposeClientManager,
63
+ // cleanup unused managers every minute
64
+ cleanupInterval: 60 * 1000,
65
+ // by default, manager is disposed after 1 hour of being unused
66
+ valueLifetime: (_a = this._initProps.unusedClientLifetime) !== null && _a !== void 0 ? _a : 60 * 60 * 1000,
67
+ // add some logging
68
+ onCreated: /* istanbul ignore next */ (id) => { var _a; return core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.PresentationManager, `Created a PresentationManager instance with ID: ${id}. Total instances: ${(_a = this._clientsStorage) === null || _a === void 0 ? void 0 : _a.values.length}.`); },
69
+ onDisposedSingle: /* istanbul ignore next */ (id) => { var _a; return core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.PresentationManager, `Disposed PresentationManager instance with ID: ${id}. Total instances: ${(_a = this._clientsStorage) === null || _a === void 0 ? void 0 : _a.values.length}.`); },
70
+ onDisposedAll: /* istanbul ignore next */ () => core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.PresentationManager, `Disposed all PresentationManager instances.`),
71
+ });
72
+ }
73
+ }
74
+ /**
75
+ * Terminates Presentation. Consumers don't need to call this as it's automatically
76
+ * called on [IModelHost.onBeforeShutdown]($core-backend) event.
77
+ */
78
+ static terminate() {
79
+ if (this._clientsStorage) {
80
+ this._clientsStorage.dispose();
81
+ this._clientsStorage = undefined;
82
+ }
83
+ if (this._shutdownListener) {
84
+ this._shutdownListener();
85
+ this._shutdownListener = undefined;
86
+ }
87
+ if (this._manager) {
88
+ this._manager.dispose();
89
+ this._manager = undefined;
90
+ }
91
+ core_common_1.RpcManager.unregisterImpl(presentation_common_1.PresentationRpcInterface);
92
+ if (this._disposeIpcHandler) {
93
+ this._disposeIpcHandler();
94
+ }
95
+ this._initProps = undefined;
96
+ if (this._requestTimeout)
97
+ this._requestTimeout = undefined;
98
+ }
99
+ static createClientManager(clientId) {
100
+ let manager;
101
+ if (Presentation._initProps && !isSingleManagerProps(Presentation._initProps) && Presentation._initProps.clientManagerFactory)
102
+ manager = Presentation._initProps.clientManagerFactory(clientId, Presentation._initProps);
103
+ else
104
+ manager = new PresentationManager_1.PresentationManager(Presentation._initProps);
105
+ return { manager };
106
+ }
107
+ static disposeClientManager(storeItem) {
108
+ storeItem.manager.dispose();
109
+ }
110
+ /**
111
+ * Get an instance of [[PresentationManager]] for specific client
112
+ * @param clientId ID of the client requesting presentation data. If no
113
+ * ID is provided, the default [[PresentationManager]] is returned.
114
+ */
115
+ static getManager(clientId) {
116
+ if (this._initProps && isSingleManagerProps(this._initProps) && this._manager)
117
+ return this._manager;
118
+ if (this._clientsStorage)
119
+ return this._clientsStorage.getValue(clientId || "").manager;
120
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.NotInitialized, "Presentation must be first initialized by calling Presentation.initialize");
121
+ }
122
+ /**
123
+ * Get the time in milliseconds that backend should respond in .
124
+ */
125
+ static getRequestTimeout() {
126
+ if (this._requestTimeout === undefined)
127
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.NotInitialized, "Presentation must be first initialized by calling Presentation.initialize");
128
+ return this._requestTimeout;
129
+ }
130
+ }
131
+ exports.Presentation = Presentation;
132
+ function isSingleManagerProps(props) {
133
+ return !!props.useSingleManager;
134
+ }
135
+ //# sourceMappingURL=Presentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Presentation.js","sourceRoot":"","sources":["../../../src/presentation-backend/Presentation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,sDAA0D;AAC1D,oDAAgD;AAChD,oEAA6G;AAC7G,mEAA4E;AAC5E,qEAAkE;AAClE,+DAAsF;AACtF,+DAA4D;AAC5D,yDAAsD;AAEtD,MAAM,qBAAqB,GAAW,KAAK,CAAC;AAyD5C;;;;;;;;;GASG;AACH,MAAa,YAAY;IASvB,0BAA0B;IAC1B,gBAAwB,CAAC;IAEzB,+DAA+D;IACxD,MAAM,KAAK,SAAS,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAEzD;;;;;;;;OAQG;IACI,MAAM,CAAC,UAAU,CAAC,KAAyB;;QAChD,wBAAU,CAAC,YAAY,CAAC,8CAAwB,EAAE,yCAAmB,CAAC,CAAC;QACvE,IAAI,sBAAO,CAAC,OAAO,EAAE;YACnB,IAAI,CAAC,kBAAkB,GAAG,+CAAsB,CAAC,QAAQ,EAAE,CAAC;SAC7D;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG,yBAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;QACjG,IAAI,CAAC,eAAe,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS,CAA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AAI,IAAI,CAAC,QAAQ;YAC3E,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,IAAI,IAAI,CAAC,eAAe;YACtB,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC;QAE/D,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,cAAc,EAAE,2EAA2E,CAAC,CAAC;IAC9I,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,iBAAiB;QAC7B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS;YACpC,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,cAAc,EAAE,2EAA2E,CAAC,CAAC;QAC9I,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CACF;AAlHD,oCAkHC;AAED,SAAS,oBAAoB,CAAC,KAAwB;IACpD,OAAO,CAAC,CAAE,KAAwC,CAAC,gBAAgB,CAAC;AACtE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { IModelHost, IpcHost } from \"@itwin/core-backend\";\r\nimport { DisposeFunc, Logger } from \"@itwin/core-bentley\";\r\nimport { RpcManager } from \"@itwin/core-common\";\r\nimport { PresentationError, PresentationRpcInterface, PresentationStatus } from \"@itwin/presentation-common\";\r\nimport { PresentationBackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { PresentationIpcHandler } from \"./PresentationIpcHandler\";\r\nimport { PresentationManager, PresentationManagerProps } from \"./PresentationManager\";\r\nimport { PresentationRpcImpl } from \"./PresentationRpcImpl\";\r\nimport { TemporaryStorage } from \"./TemporaryStorage\";\r\n\r\nconst defaultRequestTimeout: number = 90000;\r\n\r\n/**\r\n * Props for initializing the [[Presentation]] library for using multiple [[PresentationManager]]\r\n * instances, one for each frontend.\r\n *\r\n * @public\r\n */\r\nexport interface MultiManagerPresentationProps extends PresentationManagerProps {\r\n /**\r\n * Factory method for creating separate managers for each client\r\n * @internal\r\n */\r\n clientManagerFactory?: (clientId: string, props: PresentationManagerProps) => PresentationManager;\r\n\r\n /**\r\n * Time in milliseconds after which the request will timeout.\r\n */\r\n requestTimeout?: number;\r\n\r\n /**\r\n * How much time should an unused client manager be stored in memory\r\n * before it's disposed.\r\n */\r\n unusedClientLifetime?: number;\r\n}\r\n\r\n/**\r\n * Props for initializing the [[Presentation]] library with ability to use a single\r\n * [[PresentationManager]] instance for handling all requests.\r\n *\r\n * @public\r\n */\r\nexport interface SingleManagerPresentationProps extends PresentationManagerProps {\r\n /**\r\n * How much time should an unused client manager be stored in memory\r\n * before it's disposed.\r\n */\r\n requestTimeout?: number;\r\n\r\n /**\r\n * Specifies to use single manager for all clients.\r\n * @alpha\r\n */\r\n useSingleManager?: boolean;\r\n}\r\n\r\n/**\r\n * Properties that can be used to configure [[Presentation]] API\r\n * @public\r\n */\r\nexport type PresentationProps = MultiManagerPresentationProps | SingleManagerPresentationProps;\r\n\r\ninterface ClientStoreItem {\r\n manager: PresentationManager;\r\n}\r\n\r\n/**\r\n * Static class used to statically set up Presentation library for the backend.\r\n * Basically what it does is:\r\n * - Register a RPC implementation\r\n * - Create a singleton [[PresentationManager]] instance\r\n * - Subscribe for [IModelHost.onBeforeShutdown]($core-backend) event and terminate\r\n * the presentation manager when that happens.\r\n *\r\n * @public\r\n */\r\nexport class Presentation {\r\n\r\n private static _initProps: PresentationProps | undefined;\r\n private static _clientsStorage: TemporaryStorage<ClientStoreItem> | undefined;\r\n private static _requestTimeout: number | undefined;\r\n private static _disposeIpcHandler: DisposeFunc | undefined;\r\n private static _shutdownListener: DisposeFunc | undefined;\r\n private static _manager: PresentationManager | undefined;\r\n\r\n /* istanbul ignore next */\r\n private constructor() { }\r\n\r\n /** Properties used to initialize the presentation framework */\r\n public static get initProps() { return this._initProps; }\r\n\r\n /**\r\n * Initializes Presentation library for the backend.\r\n *\r\n * See [this]($docs/presentation/Setup/index.md#backend) for an example.\r\n *\r\n * **Important:** The method should be called after a call to [IModelHost.startup]($core-backend)\r\n *\r\n * @param props Optional properties for [[PresentationManager]]\r\n */\r\n public static initialize(props?: PresentationProps): void {\r\n RpcManager.registerImpl(PresentationRpcInterface, PresentationRpcImpl);\r\n if (IpcHost.isValid) {\r\n this._disposeIpcHandler = PresentationIpcHandler.register();\r\n }\r\n this._initProps = props || {};\r\n this._shutdownListener = IModelHost.onBeforeShutdown.addListener(() => Presentation.terminate());\r\n this._requestTimeout = (props && props.requestTimeout !== undefined)\r\n ? props.requestTimeout\r\n : defaultRequestTimeout;\r\n\r\n if (isSingleManagerProps(this._initProps)) {\r\n this._manager = new PresentationManager(Presentation._initProps);\r\n } else {\r\n this._clientsStorage = new TemporaryStorage<ClientStoreItem>({\r\n factory: this.createClientManager,\r\n cleanupHandler: this.disposeClientManager,\r\n // cleanup unused managers every minute\r\n cleanupInterval: 60 * 1000,\r\n // by default, manager is disposed after 1 hour of being unused\r\n valueLifetime: this._initProps.unusedClientLifetime ?? 60 * 60 * 1000,\r\n // add some logging\r\n onCreated: /* istanbul ignore next */ (id: string) => Logger.logInfo(PresentationBackendLoggerCategory.PresentationManager, `Created a PresentationManager instance with ID: ${id}. Total instances: ${this._clientsStorage?.values.length}.`),\r\n onDisposedSingle: /* istanbul ignore next */ (id: string) => Logger.logInfo(PresentationBackendLoggerCategory.PresentationManager, `Disposed PresentationManager instance with ID: ${id}. Total instances: ${this._clientsStorage?.values.length}.`),\r\n onDisposedAll: /* istanbul ignore next */ () => Logger.logInfo(PresentationBackendLoggerCategory.PresentationManager, `Disposed all PresentationManager instances.`),\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Terminates Presentation. Consumers don't need to call this as it's automatically\r\n * called on [IModelHost.onBeforeShutdown]($core-backend) event.\r\n */\r\n public static terminate(): void {\r\n if (this._clientsStorage) {\r\n this._clientsStorage.dispose();\r\n this._clientsStorage = undefined;\r\n }\r\n if (this._shutdownListener) {\r\n this._shutdownListener();\r\n this._shutdownListener = undefined;\r\n }\r\n if (this._manager) {\r\n this._manager.dispose();\r\n this._manager = undefined;\r\n }\r\n RpcManager.unregisterImpl(PresentationRpcInterface);\r\n if (this._disposeIpcHandler) {\r\n this._disposeIpcHandler();\r\n }\r\n this._initProps = undefined;\r\n if (this._requestTimeout)\r\n this._requestTimeout = undefined;\r\n }\r\n\r\n private static createClientManager(clientId: string): ClientStoreItem {\r\n let manager: PresentationManager;\r\n if (Presentation._initProps && !isSingleManagerProps(Presentation._initProps) && Presentation._initProps.clientManagerFactory)\r\n manager = Presentation._initProps.clientManagerFactory(clientId, Presentation._initProps);\r\n else\r\n manager = new PresentationManager(Presentation._initProps);\r\n return { manager };\r\n }\r\n\r\n private static disposeClientManager(storeItem: ClientStoreItem) {\r\n storeItem.manager.dispose();\r\n }\r\n\r\n /**\r\n * Get an instance of [[PresentationManager]] for specific client\r\n * @param clientId ID of the client requesting presentation data. If no\r\n * ID is provided, the default [[PresentationManager]] is returned.\r\n */\r\n public static getManager(clientId?: string): PresentationManager {\r\n if (this._initProps && isSingleManagerProps(this._initProps) && this._manager)\r\n return this._manager;\r\n if (this._clientsStorage)\r\n return this._clientsStorage.getValue(clientId || \"\").manager;\r\n\r\n throw new PresentationError(PresentationStatus.NotInitialized, \"Presentation must be first initialized by calling Presentation.initialize\");\r\n }\r\n\r\n /**\r\n * Get the time in milliseconds that backend should respond in .\r\n */\r\n public static getRequestTimeout(): number {\r\n if (this._requestTimeout === undefined)\r\n throw new PresentationError(PresentationStatus.NotInitialized, \"Presentation must be first initialized by calling Presentation.initialize\");\r\n return this._requestTimeout;\r\n }\r\n}\r\n\r\nfunction isSingleManagerProps(props: PresentationProps): props is SingleManagerPresentationProps {\r\n return !!(props as SingleManagerPresentationProps).useSingleManager;\r\n}\r\n"]}
@@ -0,0 +1,13 @@
1
+ /** @packageDocumentation
2
+ * @module RPC
3
+ */
4
+ import { IpcHandler } from "@itwin/core-backend";
5
+ import { NodeKeyJSON, PresentationIpcInterface, RulesetVariableJSON, SetRulesetVariableParams, UnsetRulesetVariableParams, UpdateHierarchyStateParams } from "@itwin/presentation-common";
6
+ /** @internal */
7
+ export declare class PresentationIpcHandler extends IpcHandler implements PresentationIpcInterface {
8
+ channelName: string;
9
+ setRulesetVariable(params: SetRulesetVariableParams<RulesetVariableJSON>): Promise<void>;
10
+ unsetRulesetVariable(params: UnsetRulesetVariableParams): Promise<void>;
11
+ updateHierarchyState(params: UpdateHierarchyStateParams<NodeKeyJSON>): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=PresentationIpcHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresentationIpcHandler.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/PresentationIpcHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAY,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACL,WAAW,EAAiC,wBAAwB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,0BAA0B,EAC/I,0BAA0B,EAC3B,MAAM,4BAA4B,CAAC;AAIpC,gBAAgB;AAChB,qBAAa,sBAAuB,SAAQ,UAAW,YAAW,wBAAwB;IACjF,WAAW,SAAiC;IAEtC,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxF,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvE,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAUlG"}
@@ -0,0 +1,41 @@
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 RPC
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PresentationIpcHandler = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_backend_1 = require("@itwin/core-backend");
13
+ const presentation_common_1 = require("@itwin/presentation-common");
14
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
15
+ const Presentation_1 = require("./Presentation");
16
+ /** @internal */
17
+ class PresentationIpcHandler extends core_backend_1.IpcHandler {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.channelName = presentation_common_1.PRESENTATION_IPC_CHANNEL_NAME;
21
+ }
22
+ async setRulesetVariable(params) {
23
+ const { clientId, rulesetId, variable } = params;
24
+ Presentation_1.Presentation.getManager(clientId).vars(rulesetId).setValue(variable.id, variable.type, variable.value);
25
+ }
26
+ async unsetRulesetVariable(params) {
27
+ const { clientId, rulesetId, variableId } = params;
28
+ Presentation_1.Presentation.getManager(clientId).vars(rulesetId).unset(variableId);
29
+ }
30
+ async updateHierarchyState(params) {
31
+ const { clientId, imodelKey, rulesetId, changeType, nodeKeys } = params;
32
+ const imodelDb = core_backend_1.IModelDb.tryFindByKey(imodelKey);
33
+ if (!imodelDb) {
34
+ core_bentley_1.Logger.logError(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Ipc, "Could not find IModelDb to perform hierarchy state update");
35
+ return;
36
+ }
37
+ Presentation_1.Presentation.getManager(clientId).getNativePlatform().updateHierarchyState(imodelDb.nativeDb, rulesetId, changeType, JSON.stringify(nodeKeys));
38
+ }
39
+ }
40
+ exports.PresentationIpcHandler = PresentationIpcHandler;
41
+ //# sourceMappingURL=PresentationIpcHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresentationIpcHandler.js","sourceRoot":"","sources":["../../../src/presentation-backend/PresentationIpcHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AA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,CAAC;IACjJ,CAAC;CACF;AAvBD,wDAuBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RPC\r\n */\r\n\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport { IModelDb, IpcHandler } from \"@itwin/core-backend\";\r\nimport {\r\n NodeKeyJSON, PRESENTATION_IPC_CHANNEL_NAME, PresentationIpcInterface, RulesetVariableJSON, SetRulesetVariableParams, UnsetRulesetVariableParams,\r\n UpdateHierarchyStateParams,\r\n} from \"@itwin/presentation-common\";\r\nimport { PresentationBackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { Presentation } from \"./Presentation\";\r\n\r\n/** @internal */\r\nexport class PresentationIpcHandler extends IpcHandler implements PresentationIpcInterface {\r\n public channelName = PRESENTATION_IPC_CHANNEL_NAME;\r\n\r\n public async setRulesetVariable(params: SetRulesetVariableParams<RulesetVariableJSON>): Promise<void> {\r\n const { clientId, rulesetId, variable } = params;\r\n Presentation.getManager(clientId).vars(rulesetId).setValue(variable.id, variable.type, variable.value);\r\n }\r\n\r\n public async unsetRulesetVariable(params: UnsetRulesetVariableParams): Promise<void> {\r\n const { clientId, rulesetId, variableId } = params;\r\n Presentation.getManager(clientId).vars(rulesetId).unset(variableId);\r\n }\r\n\r\n public async updateHierarchyState(params: UpdateHierarchyStateParams<NodeKeyJSON>): Promise<void> {\r\n const { clientId, imodelKey, rulesetId, changeType, nodeKeys } = params;\r\n const imodelDb = IModelDb.tryFindByKey(imodelKey);\r\n if (!imodelDb) {\r\n Logger.logError(PresentationBackendLoggerCategory.Ipc, \"Could not find IModelDb to perform hierarchy state update\");\r\n\r\n return;\r\n }\r\n Presentation.getManager(clientId).getNativePlatform().updateHierarchyState(imodelDb.nativeDb, rulesetId, changeType, JSON.stringify(nodeKeys));\r\n }\r\n}\r\n"]}