@itwin/presentation-backend 3.0.0-extension.1 → 3.0.2
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.
- package/CHANGELOG.md +117 -2
- package/LICENSE.md +1 -1
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +2 -2
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +36 -17
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.d.ts +1 -1
- package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.js +24 -22
- package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js +2 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.d.ts +14 -3
- package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.js +39 -18
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +15 -8
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +113 -48
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.js +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +67 -16
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/TemporaryStorage.js +81 -21
- package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -1
- package/package.json +19 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,121 @@
|
|
|
1
1
|
# Change Log - @itwin/presentation-backend
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 10 Mar 2022 21:18:13 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 3.0.2
|
|
6
|
+
Thu, 10 Mar 2022 21:18:13 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Fix RPC requests' memoization causing similar requests to different iModels to be memoized as a single request.
|
|
11
|
+
|
|
12
|
+
## 3.0.1
|
|
13
|
+
Thu, 24 Feb 2022 15:26:55 GMT
|
|
14
|
+
|
|
15
|
+
_Version update only_
|
|
16
|
+
|
|
17
|
+
## 3.0.0
|
|
18
|
+
Mon, 24 Jan 2022 14:00:52 GMT
|
|
19
|
+
|
|
20
|
+
### Updates
|
|
21
|
+
|
|
22
|
+
- Existing ruleset configurations were updated to no longer use deprecated rule versions for iModel.js 3.0.
|
|
23
|
+
- Upgrade target to ES2019
|
|
24
|
+
- fix ecsql row format
|
|
25
|
+
- rename to @itwin/presentation-backend
|
|
26
|
+
- remove ClientRequestContext and its subclasses
|
|
27
|
+
- Clean up deprecated APIs
|
|
28
|
+
- Added API to get properties of all elements.
|
|
29
|
+
- Added `PresentationManager.getContentSources` API to retrieve information about where content for specific types of elements comes from.
|
|
30
|
+
- Fix class and schema names in RelatedProperties rule for ElementOwnsUniqueAspect relationship.
|
|
31
|
+
- Fix Presentation IPC handler not being registered until the first Presentation request is made.
|
|
32
|
+
- Enforce valid page options on getElementProperties request when requesting properties of multiple elements.
|
|
33
|
+
- Fix for getElementProperties request when requesting all elements of specific classes
|
|
34
|
+
- Use async iterator when getting properties of multiple elements.
|
|
35
|
+
- Add `getContentInstanceKeys` RPC to efficiently get content instance keys.
|
|
36
|
+
- Restructure backend's initialization props
|
|
37
|
+
- Remove `PresentationManager.loadHierarchy` API.
|
|
38
|
+
- Fix ruleset variables storing in IPC apps
|
|
39
|
+
- Updated `RulesetEmbedder` to allow calling callbacks before and after Model/Element is inserted or updated
|
|
40
|
+
- Changed uses of `PresentationUnitSystem` to `UnitSystemKey`.
|
|
41
|
+
- Always create unique ruleset id when handling nodes requests
|
|
42
|
+
- remove ClientRequestContext.current
|
|
43
|
+
- remove requestContext argument from importSchemas
|
|
44
|
+
|
|
45
|
+
## 2.19.28
|
|
46
|
+
Wed, 12 Jan 2022 14:52:38 GMT
|
|
47
|
+
|
|
48
|
+
_Version update only_
|
|
49
|
+
|
|
50
|
+
## 2.19.27
|
|
51
|
+
Wed, 05 Jan 2022 20:07:20 GMT
|
|
52
|
+
|
|
53
|
+
_Version update only_
|
|
54
|
+
|
|
55
|
+
## 2.19.26
|
|
56
|
+
Wed, 08 Dec 2021 20:54:53 GMT
|
|
57
|
+
|
|
58
|
+
_Version update only_
|
|
59
|
+
|
|
60
|
+
## 2.19.25
|
|
61
|
+
Fri, 03 Dec 2021 20:05:49 GMT
|
|
62
|
+
|
|
63
|
+
_Version update only_
|
|
64
|
+
|
|
65
|
+
## 2.19.24
|
|
66
|
+
Mon, 29 Nov 2021 18:44:31 GMT
|
|
67
|
+
|
|
68
|
+
_Version update only_
|
|
69
|
+
|
|
70
|
+
## 2.19.23
|
|
71
|
+
Mon, 22 Nov 2021 20:41:40 GMT
|
|
72
|
+
|
|
73
|
+
_Version update only_
|
|
74
|
+
|
|
75
|
+
## 2.19.22
|
|
76
|
+
Wed, 17 Nov 2021 01:23:26 GMT
|
|
77
|
+
|
|
78
|
+
_Version update only_
|
|
79
|
+
|
|
80
|
+
## 2.19.21
|
|
81
|
+
Wed, 10 Nov 2021 10:58:24 GMT
|
|
82
|
+
|
|
83
|
+
_Version update only_
|
|
84
|
+
|
|
85
|
+
## 2.19.20
|
|
86
|
+
Fri, 29 Oct 2021 16:14:22 GMT
|
|
87
|
+
|
|
88
|
+
_Version update only_
|
|
89
|
+
|
|
90
|
+
## 2.19.19
|
|
91
|
+
Mon, 25 Oct 2021 16:16:25 GMT
|
|
92
|
+
|
|
93
|
+
_Version update only_
|
|
94
|
+
|
|
95
|
+
## 2.19.18
|
|
96
|
+
Thu, 21 Oct 2021 20:59:44 GMT
|
|
97
|
+
|
|
98
|
+
_Version update only_
|
|
99
|
+
|
|
100
|
+
## 2.19.17
|
|
101
|
+
Thu, 14 Oct 2021 21:19:43 GMT
|
|
102
|
+
|
|
103
|
+
_Version update only_
|
|
104
|
+
|
|
105
|
+
## 2.19.16
|
|
106
|
+
Mon, 11 Oct 2021 17:37:46 GMT
|
|
107
|
+
|
|
108
|
+
_Version update only_
|
|
109
|
+
|
|
110
|
+
## 2.19.15
|
|
111
|
+
Fri, 08 Oct 2021 16:44:23 GMT
|
|
112
|
+
|
|
113
|
+
_Version update only_
|
|
114
|
+
|
|
115
|
+
## 2.19.14
|
|
116
|
+
Fri, 01 Oct 2021 13:07:03 GMT
|
|
117
|
+
|
|
118
|
+
_Version update only_
|
|
4
119
|
|
|
5
120
|
## 2.19.13
|
|
6
121
|
Tue, 21 Sep 2021 21:06:40 GMT
|
|
@@ -729,7 +844,7 @@ Mon, 13 May 2019 15:52:05 GMT
|
|
|
729
844
|
- Fixed `PresentationRpcImpl.computeSelection` for "model", "category" and "element" scope to return specific class names instead of "BisCore:Model", "BisCore:Category" or "BisCore:Element"
|
|
730
845
|
- Allow requesting content with descriptor overrides instead of descriptor. This allows to competely avoid a descriptor request when content customization requirements are the same for all kinds of content
|
|
731
846
|
- Do not attempt to handle transient element ids when computing selection based on scope
|
|
732
|
-
- Setup a generic context for tracking client requests, and made various related enhancements to logging, usage tracking and authorization.
|
|
847
|
+
- Setup a generic context for tracking client requests, and made various related enhancements to logging, usage tracking and authorization.
|
|
733
848
|
- Upgrade TypeDoc dependency to 0.14.2
|
|
734
849
|
|
|
735
850
|
## 0.190.0
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2017-
|
|
3
|
+
Copyright © 2017-2022 Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @module Core
|
|
3
3
|
*/
|
|
4
4
|
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
-
import { Content, ElementProperties
|
|
5
|
+
import { Content, ElementProperties } from "@itwin/presentation-common";
|
|
6
6
|
/** @internal */
|
|
7
7
|
export declare const buildElementsProperties: (content: Content | undefined) => ElementProperties[];
|
|
8
8
|
/** @internal */
|
|
9
9
|
export declare function getElementsCount(db: IModelDb, classNames?: string[]): number;
|
|
10
10
|
/** @internal */
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function iterateElementIds(db: IModelDb, classNames?: string[], limit?: number): Generator<Map<string, string[]>, void, unknown>;
|
|
12
12
|
//# sourceMappingURL=ElementPropertiesHelper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementPropertiesHelper.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/ElementPropertiesHelper.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAkB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EACgB,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ElementPropertiesHelper.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/ElementPropertiesHelper.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAkB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EACgB,OAAO,EAAE,iBAAiB,EAIhD,MAAM,4BAA4B,CAAC;AAEpC,gBAAgB;AAChB,eAAO,MAAM,uBAAuB,YAAa,OAAO,GAAG,SAAS,KAAG,iBAAiB,EAOvF,CAAC;AAEF,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAWnE;AAED,gBAAgB;AAChB,wBAAiB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,mDASrF"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module Core
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
10
|
+
exports.iterateElementIds = exports.getElementsCount = exports.buildElementsProperties = void 0;
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const presentation_common_1 = require("@itwin/presentation-common");
|
|
13
13
|
/** @internal */
|
|
@@ -21,10 +21,11 @@ const buildElementsProperties = (content) => {
|
|
|
21
21
|
exports.buildElementsProperties = buildElementsProperties;
|
|
22
22
|
/** @internal */
|
|
23
23
|
function getElementsCount(db, classNames) {
|
|
24
|
+
const filter = createElementsFilter("e", classNames);
|
|
24
25
|
const query = `
|
|
25
26
|
SELECT COUNT(e.ECInstanceId)
|
|
26
27
|
FROM bis.Element e
|
|
27
|
-
${
|
|
28
|
+
${filter ? `WHERE ${filter}` : ""}
|
|
28
29
|
`;
|
|
29
30
|
return db.withPreparedStatement(query, (stmt) => {
|
|
30
31
|
return stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW ? stmt.getValue(0).getInteger() : 0;
|
|
@@ -32,20 +33,42 @@ function getElementsCount(db, classNames) {
|
|
|
32
33
|
}
|
|
33
34
|
exports.getElementsCount = getElementsCount;
|
|
34
35
|
/** @internal */
|
|
35
|
-
function
|
|
36
|
+
function* iterateElementIds(db, classNames, limit) {
|
|
37
|
+
let lastElementId;
|
|
38
|
+
while (true) {
|
|
39
|
+
const result = queryElementIds(db, classNames, limit, lastElementId);
|
|
40
|
+
yield result.ids;
|
|
41
|
+
lastElementId = result.lastElementId;
|
|
42
|
+
if (!lastElementId)
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.iterateElementIds = iterateElementIds;
|
|
47
|
+
function queryElementIds(db, classNames, limit, lastElementId) {
|
|
48
|
+
function createWhereClause() {
|
|
49
|
+
const classFilter = createElementsFilter("e", classNames);
|
|
50
|
+
const elementFilter = lastElementId ? `e.ECInstanceId > ?` : undefined;
|
|
51
|
+
if (!classFilter && !elementFilter)
|
|
52
|
+
return "";
|
|
53
|
+
if (classFilter && elementFilter)
|
|
54
|
+
return `WHERE ${classFilter} AND ${elementFilter}`;
|
|
55
|
+
return `WHERE ${classFilter !== null && classFilter !== void 0 ? classFilter : ""} ${elementFilter !== null && elementFilter !== void 0 ? elementFilter : ""}`;
|
|
56
|
+
}
|
|
36
57
|
const query = `
|
|
37
58
|
SELECT e.ECInstanceId elId, eSchemaDef.Name || ':' || eClassDef.Name elClassName
|
|
38
59
|
FROM bis.Element e
|
|
39
60
|
LEFT JOIN meta.ECClassDef eClassDef ON eClassDef.ECInstanceId = e.ECClassId
|
|
40
61
|
LEFT JOIN meta.ECSchemaDef eSchemaDef ON eSchemaDef.ECInstanceId = eClassDef.Schema.Id
|
|
41
|
-
${
|
|
42
|
-
ORDER BY e.
|
|
43
|
-
${createElementsLimitClause(pageOptions)}
|
|
62
|
+
${createWhereClause()}
|
|
63
|
+
ORDER BY e.ECInstanceId ASC
|
|
44
64
|
`;
|
|
45
65
|
return db.withPreparedStatement(query, (stmt) => {
|
|
66
|
+
if (lastElementId)
|
|
67
|
+
stmt.bindId(1, lastElementId);
|
|
46
68
|
const ids = new Map();
|
|
47
69
|
let currentClassName = "";
|
|
48
70
|
let currentIds = [];
|
|
71
|
+
let loadedIds = 0;
|
|
49
72
|
while (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
|
|
50
73
|
const row = stmt.getRow();
|
|
51
74
|
if (!row.elId || !row.elClassName)
|
|
@@ -62,20 +85,16 @@ function getElementIdsByClass(db, classNames, pageOptions) {
|
|
|
62
85
|
}
|
|
63
86
|
}
|
|
64
87
|
currentIds.push(row.elId);
|
|
88
|
+
loadedIds++;
|
|
89
|
+
if (limit && loadedIds >= limit)
|
|
90
|
+
return { ids, lastElementId: row.elId };
|
|
65
91
|
}
|
|
66
|
-
return ids;
|
|
92
|
+
return { ids, lastElementId: undefined };
|
|
67
93
|
});
|
|
68
94
|
}
|
|
69
|
-
|
|
70
|
-
function createElementsLimitClause(pageOptions) {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
if (pageOptions === undefined || (pageOptions.size === undefined && pageOptions.start === undefined))
|
|
73
|
-
return "";
|
|
74
|
-
return `LIMIT ${(_a = pageOptions.size) !== null && _a !== void 0 ? _a : -1} OFFSET ${(_b = pageOptions.start) !== null && _b !== void 0 ? _b : 0}`;
|
|
75
|
-
}
|
|
76
|
-
function createElementsFilterClause(elementAlias, classNames) {
|
|
95
|
+
function createElementsFilter(elementAlias, classNames) {
|
|
77
96
|
if (classNames === undefined || classNames.length === 0)
|
|
78
|
-
return
|
|
97
|
+
return undefined;
|
|
79
98
|
// check if list contains only valid class names
|
|
80
99
|
const classNameRegExp = new RegExp(/^[\w]+[.:][\w]+$/);
|
|
81
100
|
const invalidName = classNames.find((name) => !name.match(classNameRegExp));
|
|
@@ -83,7 +102,7 @@ function createElementsFilterClause(elementAlias, classNames) {
|
|
|
83
102
|
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, `Encountered invalid class name - ${invalidName}.
|
|
84
103
|
Valid class name formats: "<schema name or alias>.<class name>", "<schema name or alias>:<class name>"`);
|
|
85
104
|
}
|
|
86
|
-
return
|
|
105
|
+
return `${elementAlias}.ECClassId IS (${classNames.join(",")})`;
|
|
87
106
|
}
|
|
88
107
|
class ElementPropertiesAppender {
|
|
89
108
|
constructor(_item, _onItemFinished) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementPropertiesHelper.js","sourceRoot":"","sources":["../../../src/presentation-backend/ElementPropertiesHelper.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,sDAA6D;AAC7D,oEAKoC;AAEpC,gBAAgB;AACT,MAAM,uBAAuB,GAAG,CAAC,OAA4B,EAAuB,EAAE;IAC3F,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;QAC7C,OAAO,EAAE,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI,wBAAwB,EAAE,CAAC;IAC/C,IAAA,qCAAe,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC,KAAK,CAAC;AACvB,CAAC,CAAC;AAPW,QAAA,uBAAuB,2BAOlC;AAEF,gBAAgB;AAChB,SAAgB,gBAAgB,CAAC,EAAY,EAAE,UAAqB;IAClE,MAAM,KAAK,GAAG;;;MAGV,0BAA0B,CAAC,GAAG,EAAE,UAAU,CAAC;GAC9C,CAAC;IAEF,OAAO,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC,IAAoB,EAAE,EAAE;QAC9D,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,4CAUC;AAED,gBAAgB;AAChB,SAAgB,oBAAoB,CAAC,EAAY,EAAE,UAAqB,EAAE,WAAyB;IACjG,MAAM,KAAK,GAAG;;;;;MAKV,0BAA0B,CAAC,GAAG,EAAE,UAAU,CAAC;;MAE3C,yBAAyB,CAAC,WAAW,CAAC;GACzC,CAAC;IAEF,OAAO,EAAE,CAAC,qBAAq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,CAAC;IAE9D,UAAU,CAAC,KAAsB;QACtC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;IACM,WAAW,KAAW,IAAI,CAAC,eAAe,CAAC,GAAG,EAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE7D,kBAAkB,CAAC,KAA8B;QACtD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE;YACpD,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;IACL,CAAC;IACM,qBAAqB,CAAC,KAAiC;;QAC5D,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE;YAC9C,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,MAAA,MAAA,KAAK,CAAC,YAAY,0CAAE,QAAQ,EAAE,mCAAI,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;CACF","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 { ECSqlStatement, IModelDb } from \"@itwin/core-backend\";\r\nimport { assert, DbResult, Id64 } from \"@itwin/core-bentley\";\r\nimport {\r\n CategoryDescription, Content, ElementProperties, ElementPropertiesItem, ElementPropertiesPrimitiveArrayPropertyItem, ElementPropertiesPropertyItem,\r\n ElementPropertiesStructArrayPropertyItem, IContentVisitor, Item, PageOptions, PresentationError, PresentationStatus, ProcessFieldHierarchiesProps, ProcessMergedValueProps,\r\n ProcessPrimitiveValueProps, PropertyValueFormat, StartArrayProps, StartCategoryProps, StartContentProps, StartFieldProps, StartItemProps,\r\n StartStructProps, traverseContent,\r\n} from \"@itwin/presentation-common\";\r\n\r\n/** @internal */\r\nexport const buildElementsProperties = (content: Content | undefined): ElementProperties[] => {\r\n if (!content || content.contentSet.length === 0)\r\n return [];\r\n\r\n const builder = new ElementPropertiesBuilder();\r\n traverseContent(builder, content);\r\n return builder.items;\r\n};\r\n\r\n/** @internal */\r\nexport function getElementsCount(db: IModelDb, classNames?: string[]) {\r\n const query = `\r\n SELECT COUNT(e.ECInstanceId)\r\n FROM bis.Element e\r\n ${createElementsFilterClause(\"e\", classNames)}\r\n `;\r\n\r\n return db.withPreparedStatement(query, (stmt: ECSqlStatement) => {\r\n return stmt.step() === DbResult.BE_SQLITE_ROW ? stmt.getValue(0).getInteger() : 0;\r\n });\r\n}\r\n\r\n/** @internal */\r\nexport function getElementIdsByClass(db: IModelDb, classNames?: string[], pageOptions?: PageOptions) {\r\n const query = `\r\n SELECT e.ECInstanceId elId, eSchemaDef.Name || ':' || eClassDef.Name elClassName\r\n FROM bis.Element e\r\n LEFT JOIN meta.ECClassDef eClassDef ON eClassDef.ECInstanceId = e.ECClassId\r\n LEFT JOIN meta.ECSchemaDef eSchemaDef ON eSchemaDef.ECInstanceId = eClassDef.Schema.Id\r\n ${createElementsFilterClause(\"e\", classNames)}\r\n ORDER BY e.ECClassId, e.ECInstanceId\r\n ${createElementsLimitClause(pageOptions)}\r\n `;\r\n\r\n return db.withPreparedStatement(query, (stmt: ECSqlStatement) => {\r\n const ids = new Map<string, string[]>();\r\n let currentClassName = \"\";\r\n let currentIds: string[] = [];\r\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\r\n const row = stmt.getRow();\r\n if (!row.elId || !row.elClassName)\r\n continue;\r\n\r\n if (currentClassName !== row.elClassName) {\r\n currentClassName = row.elClassName;\r\n const existingIds = ids.get(row.elClassName);\r\n if (!existingIds) {\r\n currentIds = [];\r\n ids.set(row.elClassName, currentIds);\r\n } else {\r\n currentIds = existingIds;\r\n }\r\n }\r\n currentIds.push(row.elId);\r\n }\r\n return ids;\r\n });\r\n}\r\n\r\nfunction createElementsLimitClause(pageOptions?: PageOptions) {\r\n if (pageOptions === undefined || (pageOptions.size === undefined && pageOptions.start === undefined))\r\n return \"\";\r\n\r\n return `LIMIT ${pageOptions.size ?? -1} OFFSET ${pageOptions.start ?? 0}`;\r\n}\r\n\r\nfunction createElementsFilterClause(elementAlias: string, classNames?: string[]) {\r\n if (classNames === undefined || classNames.length === 0)\r\n return \"\";\r\n\r\n // check if list contains only valid class names\r\n const classNameRegExp = new RegExp(/^[\\w]+[.:][\\w]+$/);\r\n const invalidName = classNames.find((name) => !name.match(classNameRegExp));\r\n if (invalidName) {\r\n throw new PresentationError(PresentationStatus.InvalidArgument, `Encountered invalid class name - ${invalidName}.\r\n Valid class name formats: \"<schema name or alias>.<class name>\", \"<schema name or alias>:<class name>\"`);\r\n }\r\n\r\n return `WHERE ${elementAlias}.ECClassId IS (${classNames.join(\",\")})`;\r\n}\r\n\r\ninterface IPropertiesAppender {\r\n append(label: string, item: ElementPropertiesItem): void;\r\n finish(): void;\r\n}\r\n\r\nclass ElementPropertiesAppender implements IPropertiesAppender {\r\n private _propertyItems: { [label: string]: ElementPropertiesItem } = {};\r\n private _categoryItemAppenders: { [categoryName: string]: IPropertiesAppender } = {};\r\n constructor(private _item: Item, private _onItemFinished: (item: ElementProperties) => void) { }\r\n\r\n public append(label: string, item: ElementPropertiesItem): void {\r\n this._propertyItems[label] = item;\r\n }\r\n\r\n public finish(): void {\r\n // eslint-disable-next-line guard-for-in\r\n for (const categoryName in this._categoryItemAppenders) {\r\n const appender = this._categoryItemAppenders[categoryName];\r\n appender.finish();\r\n }\r\n\r\n this._onItemFinished({\r\n class: this._item.classInfo?.label ?? \"\",\r\n id: this._item.primaryKeys[0]?.id ?? Id64.invalid,\r\n label: this._item.label.displayValue,\r\n items: this._propertyItems,\r\n });\r\n }\r\n\r\n public getCategoryAppender(parentAppender: IPropertiesAppender, category: CategoryDescription): IPropertiesAppender {\r\n let appender = this._categoryItemAppenders[category.name];\r\n if (!appender) {\r\n appender = new CategoryItemAppender(parentAppender, category);\r\n this._categoryItemAppenders[category.name] = appender;\r\n }\r\n return appender;\r\n }\r\n}\r\n\r\nclass CategoryItemAppender implements IPropertiesAppender {\r\n private _items: { [label: string]: ElementPropertiesItem } = {};\r\n constructor(private _parentAppender: IPropertiesAppender, private _category: CategoryDescription) { }\r\n public append(label: string, item: ElementPropertiesItem): void {\r\n this._items[label] = item;\r\n }\r\n public finish(): void {\r\n if (Object.keys(this._items).length === 0)\r\n return;\r\n\r\n this._parentAppender.append(this._category.label, {\r\n type: \"category\",\r\n items: this._items,\r\n });\r\n }\r\n}\r\n\r\nclass ArrayItemAppender implements IPropertiesAppender {\r\n private _items: ElementPropertiesPropertyItem[] = [];\r\n constructor(private _parentAppender: IPropertiesAppender, private _props: StartArrayProps) { }\r\n public append(_label: string, item: ElementPropertiesItem): void {\r\n assert(item.type !== \"category\");\r\n this._items.push(item);\r\n }\r\n public finish(): void {\r\n assert(this._props.valueType.valueFormat === PropertyValueFormat.Array);\r\n if (this._props.valueType.memberType.valueFormat === PropertyValueFormat.Primitive)\r\n this._parentAppender.append(this._props.hierarchy.field.label, this.createPrimitivesArray());\r\n else\r\n this._parentAppender.append(this._props.hierarchy.field.label, this.createStructsArray());\r\n }\r\n private createPrimitivesArray(): ElementPropertiesPrimitiveArrayPropertyItem {\r\n return {\r\n type: \"array\",\r\n valueType: \"primitive\",\r\n values: this._items.map((item) => {\r\n assert(item.type === \"primitive\");\r\n return item.value;\r\n }),\r\n };\r\n }\r\n private createStructsArray(): ElementPropertiesStructArrayPropertyItem {\r\n return {\r\n type: \"array\",\r\n valueType: \"struct\",\r\n values: this._items.map((item) => {\r\n assert(item.type === \"struct\");\r\n return item.members;\r\n }),\r\n };\r\n }\r\n}\r\n\r\nclass StructItemAppender implements IPropertiesAppender {\r\n private _members: { [label: string]: ElementPropertiesPropertyItem } = {};\r\n constructor(private _parentAppender: IPropertiesAppender, private _props: StartStructProps) { }\r\n public append(label: string, item: ElementPropertiesItem): void {\r\n assert(item.type !== \"category\");\r\n this._members[label] = item;\r\n }\r\n public finish(): void {\r\n assert(this._props.valueType.valueFormat === PropertyValueFormat.Struct);\r\n this._parentAppender.append(this._props.hierarchy.field.label, {\r\n type: \"struct\",\r\n members: this._members,\r\n });\r\n }\r\n}\r\n\r\nclass ElementPropertiesBuilder implements IContentVisitor {\r\n private _appendersStack: IPropertiesAppender[] = [];\r\n private _items: ElementProperties[] = [];\r\n private _elementPropertiesAppender: ElementPropertiesAppender | undefined;\r\n\r\n public get items(): ElementProperties[] {\r\n return this._items;\r\n }\r\n\r\n private get _currentAppender(): IPropertiesAppender {\r\n const appender = this._appendersStack[this._appendersStack.length - 1];\r\n assert(appender !== undefined);\r\n return appender;\r\n }\r\n\r\n public startContent(_props: StartContentProps): boolean { return true; }\r\n public finishContent(): void { }\r\n\r\n public processFieldHierarchies(_props: ProcessFieldHierarchiesProps): void { }\r\n\r\n public startItem(props: StartItemProps): boolean {\r\n this._elementPropertiesAppender = new ElementPropertiesAppender(props.item, (item) => { this._items.push(item); });\r\n this._appendersStack.push(this._elementPropertiesAppender);\r\n return true;\r\n }\r\n public finishItem(): void {\r\n this._appendersStack.pop();\r\n assert(this._elementPropertiesAppender !== undefined);\r\n this._elementPropertiesAppender.finish();\r\n this._elementPropertiesAppender = undefined;\r\n }\r\n\r\n public startCategory(props: StartCategoryProps): boolean {\r\n assert(this._elementPropertiesAppender !== undefined);\r\n this._appendersStack.push(this._elementPropertiesAppender.getCategoryAppender(this._currentAppender, props.category));\r\n return true;\r\n }\r\n public finishCategory(): void {\r\n this._appendersStack.pop();\r\n }\r\n\r\n public startField(_props: StartFieldProps): boolean { return true; }\r\n public finishField(): void { }\r\n\r\n public startStruct(props: StartStructProps): boolean {\r\n this._appendersStack.push(new StructItemAppender(this._currentAppender, props));\r\n return true;\r\n }\r\n public finishStruct(): void { this._appendersStack.pop()!.finish(); }\r\n\r\n public startArray(props: StartArrayProps): boolean {\r\n this._appendersStack.push(new ArrayItemAppender(this._currentAppender, props));\r\n return true;\r\n }\r\n public finishArray(): void { this._appendersStack.pop()!.finish(); }\r\n\r\n public processMergedValue(props: ProcessMergedValueProps): void {\r\n this._currentAppender.append(props.mergedField.label, {\r\n type: \"primitive\",\r\n value: \"\",\r\n });\r\n }\r\n public processPrimitiveValue(props: ProcessPrimitiveValueProps): void {\r\n this._currentAppender.append(props.field.label, {\r\n type: \"primitive\",\r\n value: props.displayValue?.toString() ?? \"\",\r\n });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ElementPropertiesHelper.js","sourceRoot":"","sources":["../../../src/presentation-backend/ElementPropertiesHelper.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,sDAAyE;AACzE,oEAKoC;AAEpC,gBAAgB;AACT,MAAM,uBAAuB,GAAG,CAAC,OAA4B,EAAuB,EAAE;IAC3F,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;QAC7C,OAAO,EAAE,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI,wBAAwB,EAAE,CAAC;IAC/C,IAAA,qCAAe,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC,KAAK,CAAC;AACvB,CAAC,CAAC;AAPW,QAAA,uBAAuB,2BAOlC;AAEF,gBAAgB;AAChB,SAAgB,gBAAgB,CAAC,EAAY,EAAE,UAAqB;IAClE,MAAM,MAAM,GAAG,oBAAoB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG;;;MAGV,MAAM,CAAC,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;GAClC,CAAC;IAEF,OAAO,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC,IAAoB,EAAE,EAAE;QAC9D,OAAO,IAAI,CAAC,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CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;IACM,WAAW,KAAW,IAAI,CAAC,eAAe,CAAC,GAAG,EAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE7D,kBAAkB,CAAC,KAA8B;QACtD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE;YACpD,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;IACL,CAAC;IACM,qBAAqB,CAAC,KAAiC;;QAC5D,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE;YAC9C,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,MAAA,MAAA,KAAK,CAAC,YAAY,0CAAE,QAAQ,EAAE,mCAAI,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;CACF","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 { ECSqlStatement, IModelDb } from \"@itwin/core-backend\";\r\nimport { assert, DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n CategoryDescription, Content, ElementProperties, ElementPropertiesItem, ElementPropertiesPrimitiveArrayPropertyItem, ElementPropertiesPropertyItem,\r\n ElementPropertiesStructArrayPropertyItem, IContentVisitor, Item, PresentationError, PresentationStatus, ProcessFieldHierarchiesProps, ProcessMergedValueProps,\r\n ProcessPrimitiveValueProps, PropertyValueFormat, StartArrayProps, StartCategoryProps, StartContentProps, StartFieldProps, StartItemProps,\r\n StartStructProps, traverseContent,\r\n} from \"@itwin/presentation-common\";\r\n\r\n/** @internal */\r\nexport const buildElementsProperties = (content: Content | undefined): ElementProperties[] => {\r\n if (!content || content.contentSet.length === 0)\r\n return [];\r\n\r\n const builder = new ElementPropertiesBuilder();\r\n traverseContent(builder, content);\r\n return builder.items;\r\n};\r\n\r\n/** @internal */\r\nexport function getElementsCount(db: IModelDb, classNames?: string[]) {\r\n const filter = createElementsFilter(\"e\", classNames);\r\n const query = `\r\n SELECT COUNT(e.ECInstanceId)\r\n FROM bis.Element e\r\n ${filter ? `WHERE ${filter}` : \"\"}\r\n `;\r\n\r\n return db.withPreparedStatement(query, (stmt: ECSqlStatement) => {\r\n return stmt.step() === DbResult.BE_SQLITE_ROW ? stmt.getValue(0).getInteger() : 0;\r\n });\r\n}\r\n\r\n/** @internal */\r\nexport function* iterateElementIds(db: IModelDb, classNames?: string[], limit?: number) {\r\n let lastElementId;\r\n while (true) {\r\n const result = queryElementIds(db, classNames, limit, lastElementId);\r\n yield result.ids;\r\n lastElementId = result.lastElementId;\r\n if (!lastElementId)\r\n break;\r\n }\r\n}\r\n\r\nfunction queryElementIds(db: IModelDb, classNames?: string[], limit?: number, lastElementId?: Id64String) {\r\n function createWhereClause() {\r\n const classFilter = createElementsFilter(\"e\", classNames);\r\n const elementFilter = lastElementId ? `e.ECInstanceId > ?` : undefined;\r\n if (!classFilter && !elementFilter)\r\n return \"\";\r\n if (classFilter && elementFilter)\r\n return `WHERE ${classFilter} AND ${elementFilter}`;\r\n return `WHERE ${classFilter ?? \"\"} ${elementFilter ?? \"\"}`;\r\n }\r\n\r\n const query = `\r\n SELECT e.ECInstanceId elId, eSchemaDef.Name || ':' || eClassDef.Name elClassName\r\n FROM bis.Element e\r\n LEFT JOIN meta.ECClassDef eClassDef ON eClassDef.ECInstanceId = e.ECClassId\r\n LEFT JOIN meta.ECSchemaDef eSchemaDef ON eSchemaDef.ECInstanceId = eClassDef.Schema.Id\r\n ${createWhereClause()}\r\n ORDER BY e.ECInstanceId ASC\r\n `;\r\n\r\n return db.withPreparedStatement(query, (stmt: ECSqlStatement) => {\r\n if (lastElementId)\r\n stmt.bindId(1, lastElementId);\r\n\r\n const ids = new Map<string, string[]>();\r\n let currentClassName = \"\";\r\n let currentIds: string[] = [];\r\n let loadedIds = 0;\r\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\r\n const row = stmt.getRow();\r\n if (!row.elId || !row.elClassName)\r\n continue;\r\n\r\n if (currentClassName !== row.elClassName) {\r\n currentClassName = row.elClassName;\r\n const existingIds = ids.get(row.elClassName);\r\n if (!existingIds) {\r\n currentIds = [];\r\n ids.set(row.elClassName, currentIds);\r\n } else {\r\n currentIds = existingIds;\r\n }\r\n }\r\n currentIds.push(row.elId);\r\n loadedIds++;\r\n if (limit && loadedIds >= limit)\r\n return { ids, lastElementId: row.elId };\r\n }\r\n return { ids, lastElementId: undefined };\r\n });\r\n}\r\n\r\nfunction createElementsFilter(elementAlias: string, classNames?: string[]) {\r\n if (classNames === undefined || classNames.length === 0)\r\n return undefined;\r\n\r\n // check if list contains only valid class names\r\n const classNameRegExp = new RegExp(/^[\\w]+[.:][\\w]+$/);\r\n const invalidName = classNames.find((name) => !name.match(classNameRegExp));\r\n if (invalidName) {\r\n throw new PresentationError(PresentationStatus.InvalidArgument, `Encountered invalid class name - ${invalidName}.\r\n Valid class name formats: \"<schema name or alias>.<class name>\", \"<schema name or alias>:<class name>\"`);\r\n }\r\n\r\n return `${elementAlias}.ECClassId IS (${classNames.join(\",\")})`;\r\n}\r\n\r\ninterface IPropertiesAppender {\r\n append(label: string, item: ElementPropertiesItem): void;\r\n finish(): void;\r\n}\r\n\r\nclass ElementPropertiesAppender implements IPropertiesAppender {\r\n private _propertyItems: { [label: string]: ElementPropertiesItem } = {};\r\n private _categoryItemAppenders: { [categoryName: string]: IPropertiesAppender } = {};\r\n constructor(private _item: Item, private _onItemFinished: (item: ElementProperties) => void) { }\r\n\r\n public append(label: string, item: ElementPropertiesItem): void {\r\n this._propertyItems[label] = item;\r\n }\r\n\r\n public finish(): void {\r\n // eslint-disable-next-line guard-for-in\r\n for (const categoryName in this._categoryItemAppenders) {\r\n const appender = this._categoryItemAppenders[categoryName];\r\n appender.finish();\r\n }\r\n\r\n this._onItemFinished({\r\n class: this._item.classInfo?.label ?? \"\",\r\n id: this._item.primaryKeys[0]?.id ?? Id64.invalid,\r\n label: this._item.label.displayValue,\r\n items: this._propertyItems,\r\n });\r\n }\r\n\r\n public getCategoryAppender(parentAppender: IPropertiesAppender, category: CategoryDescription): IPropertiesAppender {\r\n let appender = this._categoryItemAppenders[category.name];\r\n if (!appender) {\r\n appender = new CategoryItemAppender(parentAppender, category);\r\n this._categoryItemAppenders[category.name] = appender;\r\n }\r\n return appender;\r\n }\r\n}\r\n\r\nclass CategoryItemAppender implements IPropertiesAppender {\r\n private _items: { [label: string]: ElementPropertiesItem } = {};\r\n constructor(private _parentAppender: IPropertiesAppender, private _category: CategoryDescription) { }\r\n public append(label: string, item: ElementPropertiesItem): void {\r\n this._items[label] = item;\r\n }\r\n public finish(): void {\r\n if (Object.keys(this._items).length === 0)\r\n return;\r\n\r\n this._parentAppender.append(this._category.label, {\r\n type: \"category\",\r\n items: this._items,\r\n });\r\n }\r\n}\r\n\r\nclass ArrayItemAppender implements IPropertiesAppender {\r\n private _items: ElementPropertiesPropertyItem[] = [];\r\n constructor(private _parentAppender: IPropertiesAppender, private _props: StartArrayProps) { }\r\n public append(_label: string, item: ElementPropertiesItem): void {\r\n assert(item.type !== \"category\");\r\n this._items.push(item);\r\n }\r\n public finish(): void {\r\n assert(this._props.valueType.valueFormat === PropertyValueFormat.Array);\r\n if (this._props.valueType.memberType.valueFormat === PropertyValueFormat.Primitive)\r\n this._parentAppender.append(this._props.hierarchy.field.label, this.createPrimitivesArray());\r\n else\r\n this._parentAppender.append(this._props.hierarchy.field.label, this.createStructsArray());\r\n }\r\n private createPrimitivesArray(): ElementPropertiesPrimitiveArrayPropertyItem {\r\n return {\r\n type: \"array\",\r\n valueType: \"primitive\",\r\n values: this._items.map((item) => {\r\n assert(item.type === \"primitive\");\r\n return item.value;\r\n }),\r\n };\r\n }\r\n private createStructsArray(): ElementPropertiesStructArrayPropertyItem {\r\n return {\r\n type: \"array\",\r\n valueType: \"struct\",\r\n values: this._items.map((item) => {\r\n assert(item.type === \"struct\");\r\n return item.members;\r\n }),\r\n };\r\n }\r\n}\r\n\r\nclass StructItemAppender implements IPropertiesAppender {\r\n private _members: { [label: string]: ElementPropertiesPropertyItem } = {};\r\n constructor(private _parentAppender: IPropertiesAppender, private _props: StartStructProps) { }\r\n public append(label: string, item: ElementPropertiesItem): void {\r\n assert(item.type !== \"category\");\r\n this._members[label] = item;\r\n }\r\n public finish(): void {\r\n assert(this._props.valueType.valueFormat === PropertyValueFormat.Struct);\r\n this._parentAppender.append(this._props.hierarchy.field.label, {\r\n type: \"struct\",\r\n members: this._members,\r\n });\r\n }\r\n}\r\n\r\nclass ElementPropertiesBuilder implements IContentVisitor {\r\n private _appendersStack: IPropertiesAppender[] = [];\r\n private _items: ElementProperties[] = [];\r\n private _elementPropertiesAppender: ElementPropertiesAppender | undefined;\r\n\r\n public get items(): ElementProperties[] {\r\n return this._items;\r\n }\r\n\r\n private get _currentAppender(): IPropertiesAppender {\r\n const appender = this._appendersStack[this._appendersStack.length - 1];\r\n assert(appender !== undefined);\r\n return appender;\r\n }\r\n\r\n public startContent(_props: StartContentProps): boolean { return true; }\r\n public finishContent(): void { }\r\n\r\n public processFieldHierarchies(_props: ProcessFieldHierarchiesProps): void { }\r\n\r\n public startItem(props: StartItemProps): boolean {\r\n this._elementPropertiesAppender = new ElementPropertiesAppender(props.item, (item) => { this._items.push(item); });\r\n this._appendersStack.push(this._elementPropertiesAppender);\r\n return true;\r\n }\r\n public finishItem(): void {\r\n this._appendersStack.pop();\r\n assert(this._elementPropertiesAppender !== undefined);\r\n this._elementPropertiesAppender.finish();\r\n this._elementPropertiesAppender = undefined;\r\n }\r\n\r\n public startCategory(props: StartCategoryProps): boolean {\r\n assert(this._elementPropertiesAppender !== undefined);\r\n this._appendersStack.push(this._elementPropertiesAppender.getCategoryAppender(this._currentAppender, props.category));\r\n return true;\r\n }\r\n public finishCategory(): void {\r\n this._appendersStack.pop();\r\n }\r\n\r\n public startField(_props: StartFieldProps): boolean { return true; }\r\n public finishField(): void { }\r\n\r\n public startStruct(props: StartStructProps): boolean {\r\n this._appendersStack.push(new StructItemAppender(this._currentAppender, props));\r\n return true;\r\n }\r\n public finishStruct(): void { this._appendersStack.pop()!.finish(); }\r\n\r\n public startArray(props: StartArrayProps): boolean {\r\n this._appendersStack.push(new ArrayItemAppender(this._currentAppender, props));\r\n return true;\r\n }\r\n public finishArray(): void { this._appendersStack.pop()!.finish(); }\r\n\r\n public processMergedValue(props: ProcessMergedValueProps): void {\r\n this._currentAppender.append(props.mergedField.label, {\r\n type: \"primitive\",\r\n value: \"\",\r\n });\r\n }\r\n public processPrimitiveValue(props: ProcessPrimitiveValueProps): void {\r\n this._currentAppender.append(props.field.label, {\r\n type: \"primitive\",\r\n value: props.displayValue?.toString() ?? \"\",\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -60,10 +60,10 @@ export declare type PresentationProps = MultiManagerPresentationProps | SingleMa
|
|
|
60
60
|
export declare class Presentation {
|
|
61
61
|
private static _initProps;
|
|
62
62
|
private static _clientsStorage;
|
|
63
|
-
private static _requestTimeout;
|
|
64
63
|
private static _disposeIpcHandler;
|
|
65
64
|
private static _shutdownListener;
|
|
66
65
|
private static _manager;
|
|
66
|
+
private static _rpcImpl;
|
|
67
67
|
private constructor();
|
|
68
68
|
/** Properties used to initialize the presentation framework */
|
|
69
69
|
static get initProps(): PresentationProps | undefined;
|
|
@@ -1 +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,wBAAw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G,6BAA6B,GAAG,8BAA8B,CAAC;AAM/F;;;;;;;;;GASG;AACH,qBAAa,YAAY;IAEvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAgC;IACzD,OAAO,CAAC,MAAM,CAAC,eAAe,CAA4D;IAC1F,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA0B;IAC3D,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA0B;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkC;IACzD,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;IA+BzD;;;OAGG;WACW,SAAS,IAAI,IAAI;IAwB/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"}
|
|
@@ -43,30 +43,30 @@ class Presentation {
|
|
|
43
43
|
* @param props Optional properties for [[PresentationManager]]
|
|
44
44
|
*/
|
|
45
45
|
static initialize(props) {
|
|
46
|
-
var _a;
|
|
46
|
+
var _a, _b;
|
|
47
|
+
this._initProps = props || {};
|
|
48
|
+
this._shutdownListener = core_backend_1.IModelHost.onBeforeShutdown.addListener(() => Presentation.terminate());
|
|
49
|
+
this._rpcImpl = new PresentationRpcImpl_1.PresentationRpcImpl({
|
|
50
|
+
requestTimeout: (_a = this._initProps.requestTimeout) !== null && _a !== void 0 ? _a : defaultRequestTimeout,
|
|
51
|
+
});
|
|
47
52
|
core_common_1.RpcManager.registerImpl(presentation_common_1.PresentationRpcInterface, PresentationRpcImpl_1.PresentationRpcImpl);
|
|
53
|
+
core_common_1.RpcManager.supplyImplInstance(presentation_common_1.PresentationRpcInterface, this._rpcImpl);
|
|
48
54
|
if (core_backend_1.IpcHost.isValid) {
|
|
49
55
|
this._disposeIpcHandler = PresentationIpcHandler_1.PresentationIpcHandler.register();
|
|
50
56
|
}
|
|
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
57
|
if (isSingleManagerProps(this._initProps)) {
|
|
57
58
|
this._manager = new PresentationManager_1.PresentationManager(Presentation._initProps);
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
60
|
-
this._clientsStorage = new TemporaryStorage_1.
|
|
61
|
-
factory: this.createClientManager,
|
|
61
|
+
this._clientsStorage = new TemporaryStorage_1.FactoryBasedTemporaryStorage({
|
|
62
|
+
factory: this.createClientManager.bind(this),
|
|
62
63
|
cleanupHandler: this.disposeClientManager,
|
|
63
64
|
// cleanup unused managers every minute
|
|
64
65
|
cleanupInterval: 60 * 1000,
|
|
65
66
|
// by default, manager is disposed after 1 hour of being unused
|
|
66
|
-
|
|
67
|
+
unusedValueLifetime: (_b = this._initProps.unusedClientLifetime) !== null && _b !== void 0 ? _b : 60 * 60 * 1000,
|
|
67
68
|
// add some logging
|
|
68
|
-
|
|
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}.`); },
|
|
69
|
+
onDisposedSingle: /* istanbul ignore next */ (id) => core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.PresentationManager, `Disposed PresentationManager instance with ID: ${id}. Total instances: ${this._clientsStorage.values.length}.`),
|
|
70
70
|
onDisposedAll: /* istanbul ignore next */ () => core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.PresentationManager, `Disposed all PresentationManager instances.`),
|
|
71
71
|
});
|
|
72
72
|
}
|
|
@@ -89,22 +89,24 @@ class Presentation {
|
|
|
89
89
|
this._manager = undefined;
|
|
90
90
|
}
|
|
91
91
|
core_common_1.RpcManager.unregisterImpl(presentation_common_1.PresentationRpcInterface);
|
|
92
|
+
if (this._rpcImpl) {
|
|
93
|
+
this._rpcImpl.dispose();
|
|
94
|
+
this._rpcImpl = undefined;
|
|
95
|
+
}
|
|
92
96
|
if (this._disposeIpcHandler) {
|
|
93
97
|
this._disposeIpcHandler();
|
|
94
98
|
}
|
|
95
99
|
this._initProps = undefined;
|
|
96
|
-
if (this._requestTimeout)
|
|
97
|
-
this._requestTimeout = undefined;
|
|
98
100
|
}
|
|
99
|
-
static createClientManager(clientId) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
static createClientManager(clientId, onManagerUsed) {
|
|
102
|
+
const manager = (Presentation._initProps && !isSingleManagerProps(Presentation._initProps) && Presentation._initProps.clientManagerFactory)
|
|
103
|
+
? Presentation._initProps.clientManagerFactory(clientId, Presentation._initProps)
|
|
104
|
+
: new PresentationManager_1.PresentationManager(Presentation._initProps);
|
|
105
|
+
manager.setOnManagerUsedHandler(onManagerUsed);
|
|
106
|
+
core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.PresentationManager, `Created a PresentationManager instance with ID: ${clientId}. Total instances: ${this._clientsStorage.values.length}.`);
|
|
105
107
|
return { manager };
|
|
106
108
|
}
|
|
107
|
-
static disposeClientManager(storeItem) {
|
|
109
|
+
static disposeClientManager(_id, storeItem) {
|
|
108
110
|
storeItem.manager.dispose();
|
|
109
111
|
}
|
|
110
112
|
/**
|
|
@@ -123,9 +125,9 @@ class Presentation {
|
|
|
123
125
|
* Get the time in milliseconds that backend should respond in .
|
|
124
126
|
*/
|
|
125
127
|
static getRequestTimeout() {
|
|
126
|
-
if (this.
|
|
128
|
+
if (this._rpcImpl === undefined)
|
|
127
129
|
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.NotInitialized, "Presentation must be first initialized by calling Presentation.initialize");
|
|
128
|
-
return this.
|
|
130
|
+
return this._rpcImpl.requestTimeout;
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
exports.Presentation = Presentation;
|
|
@@ -1 +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,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UAAU,IAAI,oBAAoB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,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).useSingle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C,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,QAAQ,KAAK,SAAS;YAC7B,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,cAAc,EAAE,2EAA2E,CAAC,CAAC;QAC9I,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;IACtC,CAAC;CACF;AAtHD,oCAsHC;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 { FactoryBasedTemporaryStorage } 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: FactoryBasedTemporaryStorage<ClientStoreItem> | undefined;\r\n private static _disposeIpcHandler: DisposeFunc | undefined;\r\n private static _shutdownListener: DisposeFunc | undefined;\r\n private static _manager: PresentationManager | undefined;\r\n private static _rpcImpl: PresentationRpcImpl | 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 this._initProps = props || {};\r\n this._shutdownListener = IModelHost.onBeforeShutdown.addListener(() => Presentation.terminate());\r\n\r\n this._rpcImpl = new PresentationRpcImpl({\r\n requestTimeout: this._initProps.requestTimeout ?? defaultRequestTimeout,\r\n });\r\n RpcManager.registerImpl(PresentationRpcInterface, PresentationRpcImpl);\r\n RpcManager.supplyImplInstance(PresentationRpcInterface, this._rpcImpl);\r\n\r\n if (IpcHost.isValid) {\r\n this._disposeIpcHandler = PresentationIpcHandler.register();\r\n }\r\n\r\n if (isSingleManagerProps(this._initProps)) {\r\n this._manager = new PresentationManager(Presentation._initProps);\r\n } else {\r\n this._clientsStorage = new FactoryBasedTemporaryStorage<ClientStoreItem>({\r\n factory: this.createClientManager.bind(this),\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 unusedValueLifetime: this._initProps.unusedClientLifetime ?? 60 * 60 * 1000,\r\n // add some logging\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._rpcImpl) {\r\n this._rpcImpl.dispose();\r\n this._rpcImpl = undefined;\r\n }\r\n if (this._disposeIpcHandler) {\r\n this._disposeIpcHandler();\r\n }\r\n this._initProps = undefined;\r\n }\r\n\r\n private static createClientManager(clientId: string, onManagerUsed: () => void): ClientStoreItem {\r\n const manager = (Presentation._initProps && !isSingleManagerProps(Presentation._initProps) && Presentation._initProps.clientManagerFactory)\r\n ? Presentation._initProps.clientManagerFactory(clientId, Presentation._initProps)\r\n : new PresentationManager(Presentation._initProps);\r\n manager.setOnManagerUsedHandler(onManagerUsed);\r\n Logger.logInfo(PresentationBackendLoggerCategory.PresentationManager, `Created a PresentationManager instance with ID: ${clientId}. Total instances: ${this._clientsStorage!.values.length}.`);\r\n return { manager };\r\n }\r\n\r\n private static disposeClientManager(_id: string, 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._rpcImpl === undefined)\r\n throw new PresentationError(PresentationStatus.NotInitialized, \"Presentation must be first initialized by calling Presentation.initialize\");\r\n return this._rpcImpl.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"]}
|
|
@@ -1 +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,
|
|
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,EAAmB,mBAAmB,EAAE,wBAAwB,EACpI,0BAA0B,EAAE,0BAA0B,EACvD,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;IAMxF,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"}
|
|
@@ -21,7 +21,8 @@ class PresentationIpcHandler extends core_backend_1.IpcHandler {
|
|
|
21
21
|
}
|
|
22
22
|
async setRulesetVariable(params) {
|
|
23
23
|
const { clientId, rulesetId, variable } = params;
|
|
24
|
-
|
|
24
|
+
const parsedVariable = presentation_common_1.RulesetVariable.fromJSON(variable);
|
|
25
|
+
Presentation_1.Presentation.getManager(clientId).vars(rulesetId).setValue(parsedVariable.id, parsedVariable.type, parsedVariable.value);
|
|
25
26
|
}
|
|
26
27
|
async unsetRulesetVariable(params) {
|
|
27
28
|
const { clientId, rulesetId, variableId } = params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresentationIpcHandler.js","sourceRoot":"","sources":["../../../src/presentation-backend/PresentationIpcHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,sDAA2D;AAC3D,oEAGoC;AACpC,mEAA4E;AAC5E,iDAA8C;AAE9C,gBAAgB;AAChB,MAAa,sBAAuB,SAAQ,yBAAU;IAAtD;;QACS,gBAAW,GAAG,mDAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"PresentationIpcHandler.js","sourceRoot":"","sources":["../../../src/presentation-backend/PresentationIpcHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,sDAA2D;AAC3D,oEAGoC;AACpC,mEAA4E;AAC5E,iDAA8C;AAE9C,gBAAgB;AAChB,MAAa,sBAAuB,SAAQ,yBAAU;IAAtD;;QACS,gBAAW,GAAG,mDAA6B,CAAC;IAuBrD,CAAC;IArBQ,KAAK,CAAC,kBAAkB,CAAC,MAAqD;QACnF,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QACjD,MAAM,cAAc,GAAG,qCAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC1D,2BAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3H,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,MAAkC;QAClE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QACnD,2BAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACtE,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,MAA+C;QAC/E,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QACxE,MAAM,QAAQ,GAAG,uBAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,EAAE;YACb,qBAAM,CAAC,QAAQ,CAAC,yDAAiC,CAAC,GAAG,EAAE,2DAA2D,CAAC,CAAC;YAEpH,OAAO;SACR;QACD,2BAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,iBAAiB,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjJ,CAAC;CACF;AAxBD,wDAwBC","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, RulesetVariable, RulesetVariableJSON, SetRulesetVariableParams,\r\n UnsetRulesetVariableParams, 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 const parsedVariable = RulesetVariable.fromJSON(variable);\r\n Presentation.getManager(clientId).vars(rulesetId).setValue(parsedVariable.id, parsedVariable.type, parsedVariable.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"]}
|
|
@@ -113,6 +113,14 @@ export interface UnitSystemFormat {
|
|
|
113
113
|
unitSystems: UnitSystemKey[];
|
|
114
114
|
format: FormatProps;
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Data structure for multiple element properties request response.
|
|
118
|
+
* @alpha
|
|
119
|
+
*/
|
|
120
|
+
export interface MultiElementPropertiesResponse {
|
|
121
|
+
total: number;
|
|
122
|
+
iterator: () => AsyncGenerator<ElementProperties[]>;
|
|
123
|
+
}
|
|
116
124
|
/**
|
|
117
125
|
* Properties that can be used to configure [[PresentationManager]]
|
|
118
126
|
* @public
|
|
@@ -252,6 +260,7 @@ export declare class PresentationManager {
|
|
|
252
260
|
private _isDisposed;
|
|
253
261
|
private _disposeIModelOpenedListener?;
|
|
254
262
|
private _updatesTracker?;
|
|
263
|
+
private _onManagerUsed?;
|
|
255
264
|
/** Get / set active locale used for localizing presentation data */
|
|
256
265
|
activeLocale: string | undefined;
|
|
257
266
|
/** Get / set active unit system used to format property values with units */
|
|
@@ -265,6 +274,8 @@ export declare class PresentationManager {
|
|
|
265
274
|
* Dispose the presentation manager. Must be called to clean up native resources.
|
|
266
275
|
*/
|
|
267
276
|
dispose(): void;
|
|
277
|
+
/** @internal */
|
|
278
|
+
setOnManagerUsedHandler(handler: () => void): void;
|
|
268
279
|
/** Properties used to initialize the manager */
|
|
269
280
|
get props(): PresentationManagerProps;
|
|
270
281
|
/**
|
|
@@ -338,11 +349,11 @@ export declare class PresentationManager {
|
|
|
338
349
|
*/
|
|
339
350
|
getElementProperties(requestOptions: Prioritized<SingleElementPropertiesRequestOptions<IModelDb>>): Promise<ElementProperties | undefined>;
|
|
340
351
|
/**
|
|
341
|
-
* Retrieves property data in simplified format for multiple elements specified by class
|
|
342
|
-
*
|
|
352
|
+
* Retrieves property data in simplified format for multiple elements specified by class or all element.
|
|
353
|
+
* @return An object that contains element count and AsyncGenerator to iterate over properties of those elements in batches of undefined size.
|
|
343
354
|
* @alpha
|
|
344
355
|
*/
|
|
345
|
-
getElementProperties(requestOptions: Prioritized<MultiElementPropertiesRequestOptions<IModelDb>>): Promise<
|
|
356
|
+
getElementProperties(requestOptions: Prioritized<MultiElementPropertiesRequestOptions<IModelDb>>): Promise<MultiElementPropertiesResponse>;
|
|
346
357
|
private getMultipleElementProperties;
|
|
347
358
|
/**
|
|
348
359
|
* Retrieves display label definition of specific item
|