@itwin/presentation-backend 4.0.0-dev.8 → 4.0.0-dev.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +5 -3
- package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +41 -41
- package/lib/cjs/presentation-backend/BackendLoggerCategory.js +50 -50
- package/lib/cjs/presentation-backend/Constants.d.ts +8 -8
- package/lib/cjs/presentation-backend/Constants.js +40 -36
- package/lib/cjs/presentation-backend/Constants.js.map +1 -1
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +11 -11
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +260 -262
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.d.ts +87 -87
- package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.js +140 -140
- package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.d.ts +106 -106
- package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.js +148 -150
- package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +12 -12
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js +41 -41
- package/lib/cjs/presentation-backend/PresentationManager.d.ts +456 -445
- package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.js +309 -311
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +61 -61
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js +430 -430
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +62 -62
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +388 -388
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +102 -102
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.js +284 -279
- package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetManager.d.ts +53 -53
- package/lib/cjs/presentation-backend/RulesetManager.js +73 -73
- package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +140 -140
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js +129 -129
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +28 -28
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js +210 -213
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +123 -123
- package/lib/cjs/presentation-backend/TemporaryStorage.js +151 -151
- package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +27 -27
- package/lib/cjs/presentation-backend/UpdatesTracker.js +54 -54
- package/lib/cjs/presentation-backend/Utils.d.ts +49 -49
- package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Utils.js +107 -106
- package/lib/cjs/presentation-backend/Utils.js.map +1 -1
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +16 -16
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +55 -51
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -1
- package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +21 -21
- package/lib/cjs/presentation-backend/domain/RulesetElements.js +38 -38
- package/lib/cjs/presentation-backend.d.ts +19 -19
- package/lib/cjs/presentation-backend.js +39 -35
- package/lib/cjs/presentation-backend.js.map +1 -1
- package/package.json +18 -18
|
@@ -1,389 +1,389 @@
|
|
|
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.PresentationRpcImpl = exports.MAX_ALLOWED_KEYS_PAGE_SIZE = exports.MAX_ALLOWED_PAGE_SIZE = void 0;
|
|
11
|
-
const core_backend_1 = require("@itwin/core-backend");
|
|
12
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
|
-
const presentation_common_1 = require("@itwin/presentation-common");
|
|
14
|
-
const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
|
|
15
|
-
const Presentation_1 = require("./Presentation");
|
|
16
|
-
const TemporaryStorage_1 = require("./TemporaryStorage");
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
|
-
const packageJsonVersion = require("../../../package.json").version;
|
|
19
|
-
/** @internal */
|
|
20
|
-
exports.MAX_ALLOWED_PAGE_SIZE = 1000;
|
|
21
|
-
/** @internal */
|
|
22
|
-
exports.MAX_ALLOWED_KEYS_PAGE_SIZE = 10000;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
super();
|
|
33
|
-
this._requestTimeout =
|
|
34
|
-
this._pendingRequests = new TemporaryStorage_1.TemporaryStorage({
|
|
35
|
-
// remove the pending request after request timeout + 10 seconds - this gives
|
|
36
|
-
// frontend 10 seconds to re-send the request until it's removed from requests' cache
|
|
37
|
-
unusedValueLifetime: (this._requestTimeout > 0) ? (this._requestTimeout + 10 * 1000) : undefined,
|
|
38
|
-
// attempt to clean up every second
|
|
39
|
-
cleanupInterval: 1000,
|
|
40
|
-
cleanupHandler: (id, _, reason) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
get
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.getManager(requestOptions.clientId).
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
this.getManager(requestOptions.clientId).
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
this.getManager(requestOptions.clientId).
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const validPageSize = getValidPageSize(
|
|
374
|
-
if (!requestOptions.paging || requestOptions.paging.size !== validPageSize)
|
|
375
|
-
return { ...requestOptions, paging: { ...requestOptions.paging, size: validPageSize } };
|
|
376
|
-
return requestOptions;
|
|
377
|
-
};
|
|
378
|
-
const getValidPageSize = (size, maxPageSize) => {
|
|
379
|
-
const requestedSize = size
|
|
380
|
-
return (requestedSize === 0 || requestedSize > maxPageSize) ? maxPageSize : requestedSize;
|
|
381
|
-
};
|
|
382
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
383
|
-
const nodeKeyFromJson = (json) => {
|
|
384
|
-
if (!json)
|
|
385
|
-
return undefined;
|
|
386
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
387
|
-
return presentation_common_1.NodeKey.fromJSON(json);
|
|
388
|
-
};
|
|
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.PresentationRpcImpl = exports.MAX_ALLOWED_KEYS_PAGE_SIZE = exports.MAX_ALLOWED_PAGE_SIZE = void 0;
|
|
11
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
12
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
|
+
const presentation_common_1 = require("@itwin/presentation-common");
|
|
14
|
+
const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
|
|
15
|
+
const Presentation_1 = require("./Presentation");
|
|
16
|
+
const TemporaryStorage_1 = require("./TemporaryStorage");
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
|
+
const packageJsonVersion = require("../../../package.json").version;
|
|
19
|
+
/** @internal */
|
|
20
|
+
exports.MAX_ALLOWED_PAGE_SIZE = 1000;
|
|
21
|
+
/** @internal */
|
|
22
|
+
exports.MAX_ALLOWED_KEYS_PAGE_SIZE = 10000;
|
|
23
|
+
const DEFAULT_REQUEST_TIMEOUT = 5000;
|
|
24
|
+
/**
|
|
25
|
+
* The backend implementation of PresentationRpcInterface. All it's basically
|
|
26
|
+
* responsible for is forwarding calls to [[Presentation.manager]].
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
class PresentationRpcImpl extends presentation_common_1.PresentationRpcInterface {
|
|
31
|
+
constructor(props) {
|
|
32
|
+
super();
|
|
33
|
+
this._requestTimeout = props?.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
34
|
+
this._pendingRequests = new TemporaryStorage_1.TemporaryStorage({
|
|
35
|
+
// remove the pending request after request timeout + 10 seconds - this gives
|
|
36
|
+
// frontend 10 seconds to re-send the request until it's removed from requests' cache
|
|
37
|
+
unusedValueLifetime: (this._requestTimeout > 0) ? (this._requestTimeout + 10 * 1000) : undefined,
|
|
38
|
+
// attempt to clean up every second
|
|
39
|
+
cleanupInterval: 1000,
|
|
40
|
+
cleanupHandler: (id, _, reason) => {
|
|
41
|
+
if (reason !== "request") {
|
|
42
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Cleaning up request without frontend retrieving it: ${id}.`);
|
|
43
|
+
// istanbul ignore next
|
|
44
|
+
this._cancelEvents.get(id)?.raiseEvent();
|
|
45
|
+
}
|
|
46
|
+
this._cancelEvents.delete(id);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
this._cancelEvents = new Map();
|
|
50
|
+
}
|
|
51
|
+
dispose() {
|
|
52
|
+
this._pendingRequests.dispose();
|
|
53
|
+
}
|
|
54
|
+
get requestTimeout() { return this._requestTimeout; }
|
|
55
|
+
get pendingRequests() { return this._pendingRequests; }
|
|
56
|
+
/** Returns an ok response with result inside */
|
|
57
|
+
successResponse(result, diagnostics) {
|
|
58
|
+
return {
|
|
59
|
+
statusCode: presentation_common_1.PresentationStatus.Success,
|
|
60
|
+
result,
|
|
61
|
+
diagnostics,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Returns a bad request response with empty result and an error code */
|
|
65
|
+
errorResponse(errorCode, errorMessage, diagnostics) {
|
|
66
|
+
return {
|
|
67
|
+
statusCode: errorCode,
|
|
68
|
+
result: undefined,
|
|
69
|
+
errorMessage,
|
|
70
|
+
diagnostics,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the [[PresentationManager]] used by this RPC impl.
|
|
75
|
+
*/
|
|
76
|
+
getManager(clientId) {
|
|
77
|
+
return Presentation_1.Presentation.getManager(clientId);
|
|
78
|
+
}
|
|
79
|
+
getIModel(token) {
|
|
80
|
+
let imodel;
|
|
81
|
+
try {
|
|
82
|
+
imodel = core_backend_1.IModelDb.findByKey(token.key);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "IModelRpcProps doesn't point to a valid iModel");
|
|
86
|
+
}
|
|
87
|
+
return imodel;
|
|
88
|
+
}
|
|
89
|
+
async makeRequest(token, requestId, requestOptions, request) {
|
|
90
|
+
const requestKey = JSON.stringify({ iModelKey: token.key, requestId, requestOptions });
|
|
91
|
+
core_bentley_1.Logger.logInfo(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Received '${requestId}' request. Params: ${requestKey}`);
|
|
92
|
+
let resultPromise = this._pendingRequests.getValue(requestKey);
|
|
93
|
+
if (resultPromise) {
|
|
94
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Request already pending`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Request not found, creating a new one`);
|
|
98
|
+
let imodel;
|
|
99
|
+
try {
|
|
100
|
+
imodel = this.getIModel(token);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
(0, core_bentley_1.assert)(e instanceof Error);
|
|
104
|
+
return this.errorResponse(presentation_common_1.PresentationStatus.InvalidArgument, e.message);
|
|
105
|
+
}
|
|
106
|
+
const { clientId: _, diagnostics: diagnosticsOptions, rulesetVariables, ...options } = requestOptions;
|
|
107
|
+
const managerRequestOptions = {
|
|
108
|
+
...options,
|
|
109
|
+
imodel,
|
|
110
|
+
cancelEvent: new core_bentley_1.BeEvent(),
|
|
111
|
+
};
|
|
112
|
+
// set up ruleset variables
|
|
113
|
+
if (rulesetVariables)
|
|
114
|
+
managerRequestOptions.rulesetVariables = rulesetVariables.map(presentation_common_1.RulesetVariable.fromJSON);
|
|
115
|
+
// set up diagnostics listener
|
|
116
|
+
let diagnostics;
|
|
117
|
+
const getDiagnostics = () => {
|
|
118
|
+
if (!diagnostics)
|
|
119
|
+
diagnostics = {};
|
|
120
|
+
return diagnostics;
|
|
121
|
+
};
|
|
122
|
+
if (diagnosticsOptions) {
|
|
123
|
+
if (diagnosticsOptions.backendVersion) {
|
|
124
|
+
getDiagnostics().backendVersion = packageJsonVersion;
|
|
125
|
+
}
|
|
126
|
+
managerRequestOptions.diagnostics = {
|
|
127
|
+
...diagnosticsOptions,
|
|
128
|
+
handler: (d) => {
|
|
129
|
+
if (d.logs) {
|
|
130
|
+
const target = getDiagnostics();
|
|
131
|
+
if (target.logs)
|
|
132
|
+
target.logs.push(...d.logs);
|
|
133
|
+
else
|
|
134
|
+
target.logs = [...d.logs];
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// initiate request
|
|
140
|
+
resultPromise = request(managerRequestOptions)
|
|
141
|
+
.then((result) => this.successResponse(result, diagnostics))
|
|
142
|
+
.catch((e) => this.errorResponse(e.errorNumber, e.message, diagnostics));
|
|
143
|
+
// store the request promise
|
|
144
|
+
this._pendingRequests.addValue(requestKey, resultPromise);
|
|
145
|
+
this._cancelEvents.set(requestKey, managerRequestOptions.cancelEvent);
|
|
146
|
+
}
|
|
147
|
+
if (this._requestTimeout === 0) {
|
|
148
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Request timeout not configured, returning promise without a timeout.`);
|
|
149
|
+
resultPromise.finally(() => {
|
|
150
|
+
this._pendingRequests.deleteValue(requestKey);
|
|
151
|
+
});
|
|
152
|
+
return resultPromise;
|
|
153
|
+
}
|
|
154
|
+
let timeout;
|
|
155
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
156
|
+
timeout = setTimeout(() => {
|
|
157
|
+
reject();
|
|
158
|
+
}, this._requestTimeout);
|
|
159
|
+
});
|
|
160
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
161
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Returning a promise with a timeout of ${this._requestTimeout}.`);
|
|
162
|
+
return Promise
|
|
163
|
+
.race([resultPromise, timeoutPromise])
|
|
164
|
+
.catch(() => {
|
|
165
|
+
// note: error responses from the manager get handled when creating `resultPromise`, so we can only get here due
|
|
166
|
+
// to a timeout exception
|
|
167
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Request timeout, returning "BackendTimeout" status.`);
|
|
168
|
+
return this.errorResponse(presentation_common_1.PresentationStatus.BackendTimeout);
|
|
169
|
+
})
|
|
170
|
+
.then((response) => {
|
|
171
|
+
if (response.statusCode !== presentation_common_1.PresentationStatus.BackendTimeout) {
|
|
172
|
+
core_bentley_1.Logger.logTrace(BackendLoggerCategory_1.PresentationBackendLoggerCategory.Rpc, `Request completed, returning result.`);
|
|
173
|
+
this._pendingRequests.deleteValue(requestKey);
|
|
174
|
+
}
|
|
175
|
+
clearTimeout(timeout);
|
|
176
|
+
return response;
|
|
177
|
+
});
|
|
178
|
+
/* eslint-enable @typescript-eslint/indent */
|
|
179
|
+
}
|
|
180
|
+
async getNodesCount(token, requestOptions) {
|
|
181
|
+
return this.makeRequest(token, "getNodesCount", requestOptions, async (options) => {
|
|
182
|
+
options = {
|
|
183
|
+
...options,
|
|
184
|
+
parentKey: nodeKeyFromJson(options.parentKey),
|
|
185
|
+
};
|
|
186
|
+
return this.getManager(requestOptions.clientId).getNodesCount(options);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
190
|
+
async getPagedNodes(token, requestOptions) {
|
|
191
|
+
return this.makeRequest(token, "getPagedNodes", requestOptions, async (options) => {
|
|
192
|
+
options = enforceValidPageSize({
|
|
193
|
+
...options,
|
|
194
|
+
parentKey: nodeKeyFromJson(options.parentKey),
|
|
195
|
+
});
|
|
196
|
+
const [serializedNodesJson, count] = await Promise.all([
|
|
197
|
+
this.getManager(requestOptions.clientId).getDetail().getNodes(options),
|
|
198
|
+
this.getManager(requestOptions.clientId).getNodesCount(options),
|
|
199
|
+
]);
|
|
200
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
201
|
+
const nodesJson = JSON.parse(serializedNodesJson);
|
|
202
|
+
return {
|
|
203
|
+
total: count,
|
|
204
|
+
items: nodesJson.nodes,
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async getNodesDescriptor(token, requestOptions) {
|
|
209
|
+
return this.makeRequest(token, "getNodesDescriptor", requestOptions, async (options) => {
|
|
210
|
+
options = {
|
|
211
|
+
...options,
|
|
212
|
+
parentKey: nodeKeyFromJson(options.parentKey),
|
|
213
|
+
};
|
|
214
|
+
return this.getManager().getDetail().getNodesDescriptor(options);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
218
|
+
async getNodePaths(token, requestOptions) {
|
|
219
|
+
return this.makeRequest(token, "getNodePaths", requestOptions, async (options) => {
|
|
220
|
+
const result = await this.getManager(requestOptions.clientId).getNodePaths(options);
|
|
221
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
222
|
+
return result.map(presentation_common_1.NodePathElement.toJSON);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
226
|
+
async getFilteredNodePaths(token, requestOptions) {
|
|
227
|
+
return this.makeRequest(token, "getFilteredNodePaths", requestOptions, async (options) => {
|
|
228
|
+
const result = await this.getManager(requestOptions.clientId).getFilteredNodePaths(options);
|
|
229
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
230
|
+
return result.map(presentation_common_1.NodePathElement.toJSON);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async getContentSources(token, requestOptions) {
|
|
234
|
+
return this.makeRequest(token, "getContentSources", requestOptions, async (options) => {
|
|
235
|
+
const result = await this.getManager(requestOptions.clientId).getContentSources(options);
|
|
236
|
+
const classesMap = {};
|
|
237
|
+
const selectClasses = result.map((sci) => presentation_common_1.SelectClassInfo.toCompressedJSON(sci, classesMap));
|
|
238
|
+
return { sources: selectClasses, classesMap };
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async getContentDescriptor(token, requestOptions) {
|
|
242
|
+
return this.makeRequest(token, "getContentDescriptor", requestOptions, async (options) => {
|
|
243
|
+
options = {
|
|
244
|
+
...options,
|
|
245
|
+
keys: presentation_common_1.KeySet.fromJSON(options.keys),
|
|
246
|
+
};
|
|
247
|
+
if (options.transport === "unparsed-json") {
|
|
248
|
+
// Here we send a plain JSON string but we will parse it to DescriptorJSON on the frontend. This way we are
|
|
249
|
+
// bypassing unnecessary deserialization and serialization.
|
|
250
|
+
return Presentation_1.Presentation.getManager().getDetail().getContentDescriptor(options);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
// Support for older frontends that still expect a parsed descriptor
|
|
254
|
+
const descriptor = await Presentation_1.Presentation.getManager().getContentDescriptor(options);
|
|
255
|
+
return descriptor?.toJSON();
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
async getContentSetSize(token, requestOptions) {
|
|
260
|
+
return this.makeRequest(token, "getContentSetSize", requestOptions, async (options) => {
|
|
261
|
+
options = {
|
|
262
|
+
...options,
|
|
263
|
+
keys: presentation_common_1.KeySet.fromJSON(options.keys),
|
|
264
|
+
};
|
|
265
|
+
return this.getManager(requestOptions.clientId).getContentSetSize(options);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
async getPagedContent(token, requestOptions) {
|
|
269
|
+
return this.makeRequest(token, "getPagedContent", requestOptions, async (options) => {
|
|
270
|
+
options = enforceValidPageSize({
|
|
271
|
+
...options,
|
|
272
|
+
keys: presentation_common_1.KeySet.fromJSON(options.keys),
|
|
273
|
+
});
|
|
274
|
+
const [size, content] = await Promise.all([
|
|
275
|
+
this.getManager(requestOptions.clientId).getContentSetSize(options),
|
|
276
|
+
this.getManager(requestOptions.clientId).getDetail().getContent(options),
|
|
277
|
+
]);
|
|
278
|
+
if (!content)
|
|
279
|
+
return undefined;
|
|
280
|
+
return {
|
|
281
|
+
descriptor: content.descriptor.toJSON(),
|
|
282
|
+
contentSet: {
|
|
283
|
+
total: size,
|
|
284
|
+
items: content.contentSet.map((i) => i.toJSON()),
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
async getPagedContentSet(token, requestOptions) {
|
|
290
|
+
const content = await this.getPagedContent(token, requestOptions);
|
|
291
|
+
return this.successResponse(content.result ? content.result.contentSet : { total: 0, items: [] });
|
|
292
|
+
}
|
|
293
|
+
async getElementProperties(token, requestOptions) {
|
|
294
|
+
return this.makeRequest(token, "getElementProperties", { ...requestOptions }, async (options) => {
|
|
295
|
+
return this.getManager(requestOptions.clientId).getDetail().getElementProperties(options);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
299
|
+
async getPagedDistinctValues(token, requestOptions) {
|
|
300
|
+
return this.makeRequest(token, "getPagedDistinctValues", requestOptions, async (options) => {
|
|
301
|
+
options = enforceValidPageSize({
|
|
302
|
+
...options,
|
|
303
|
+
keys: presentation_common_1.KeySet.fromJSON(options.keys),
|
|
304
|
+
});
|
|
305
|
+
const response = await this.getManager(requestOptions.clientId).getPagedDistinctValues(options);
|
|
306
|
+
return {
|
|
307
|
+
...response,
|
|
308
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
309
|
+
items: response.items.map(presentation_common_1.DisplayValueGroup.toJSON),
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
async getContentInstanceKeys(token, requestOptions) {
|
|
314
|
+
return this.makeRequest(token, "getContentInstanceKeys", requestOptions, async (options) => {
|
|
315
|
+
const { displayType, ...optionsNoDisplayType } = options;
|
|
316
|
+
options = enforceValidPageSize({
|
|
317
|
+
...optionsNoDisplayType,
|
|
318
|
+
keys: presentation_common_1.KeySet.fromJSON(optionsNoDisplayType.keys),
|
|
319
|
+
descriptor: {
|
|
320
|
+
displayType,
|
|
321
|
+
contentFlags: presentation_common_1.ContentFlags.KeysOnly,
|
|
322
|
+
},
|
|
323
|
+
}, exports.MAX_ALLOWED_KEYS_PAGE_SIZE);
|
|
324
|
+
const [size, content] = await Promise.all([
|
|
325
|
+
this.getManager(requestOptions.clientId).getContentSetSize(options),
|
|
326
|
+
this.getManager(requestOptions.clientId).getDetail().getContent(options),
|
|
327
|
+
]);
|
|
328
|
+
if (size === 0 || !content)
|
|
329
|
+
return { total: 0, items: new presentation_common_1.KeySet().toJSON() };
|
|
330
|
+
return {
|
|
331
|
+
total: size,
|
|
332
|
+
items: content.contentSet.reduce((keys, item) => keys.add(item.primaryKeys), new presentation_common_1.KeySet()).toJSON(),
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
async getDisplayLabelDefinition(token, requestOptions) {
|
|
337
|
+
return this.makeRequest(token, "getDisplayLabelDefinition", requestOptions, async (options) => {
|
|
338
|
+
const label = await this.getManager(requestOptions.clientId).getDetail().getDisplayLabelDefinition(options);
|
|
339
|
+
return label;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
async getPagedDisplayLabelDefinitions(token, requestOptions) {
|
|
343
|
+
const pageOpts = enforceValidPageSize({ paging: { start: 0, size: requestOptions.keys.length } });
|
|
344
|
+
if (pageOpts.paging.size < requestOptions.keys.length)
|
|
345
|
+
requestOptions.keys.splice(pageOpts.paging.size);
|
|
346
|
+
return this.makeRequest(token, "getPagedDisplayLabelDefinitions", requestOptions, async (options) => {
|
|
347
|
+
const labels = await this.getManager(requestOptions.clientId).getDetail().getDisplayLabelDefinitions({ ...options, keys: options.keys });
|
|
348
|
+
return {
|
|
349
|
+
total: options.keys.length,
|
|
350
|
+
items: labels,
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
async getSelectionScopes(token, requestOptions) {
|
|
355
|
+
return this.makeRequest(token, "getSelectionScopes", requestOptions, async (options) => this.getManager(requestOptions.clientId).getSelectionScopes(options));
|
|
356
|
+
}
|
|
357
|
+
async computeSelection(token, requestOptions, ids, scopeId) {
|
|
358
|
+
return this.makeRequest(token, "computeSelection", requestOptions, async (options) => {
|
|
359
|
+
if (!(0, presentation_common_1.isComputeSelectionRequestOptions)(options)) {
|
|
360
|
+
options = {
|
|
361
|
+
...options,
|
|
362
|
+
elementIds: ids,
|
|
363
|
+
scope: { id: scopeId },
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
const keys = await this.getManager(requestOptions.clientId).computeSelection(options);
|
|
367
|
+
return keys.toJSON();
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
exports.PresentationRpcImpl = PresentationRpcImpl;
|
|
372
|
+
const enforceValidPageSize = (requestOptions, maxPageSize = exports.MAX_ALLOWED_PAGE_SIZE) => {
|
|
373
|
+
const validPageSize = getValidPageSize(requestOptions.paging?.size, maxPageSize);
|
|
374
|
+
if (!requestOptions.paging || requestOptions.paging.size !== validPageSize)
|
|
375
|
+
return { ...requestOptions, paging: { ...requestOptions.paging, size: validPageSize } };
|
|
376
|
+
return requestOptions;
|
|
377
|
+
};
|
|
378
|
+
const getValidPageSize = (size, maxPageSize) => {
|
|
379
|
+
const requestedSize = size ?? 0;
|
|
380
|
+
return (requestedSize === 0 || requestedSize > maxPageSize) ? maxPageSize : requestedSize;
|
|
381
|
+
};
|
|
382
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
383
|
+
const nodeKeyFromJson = (json) => {
|
|
384
|
+
if (!json)
|
|
385
|
+
return undefined;
|
|
386
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
387
|
+
return presentation_common_1.NodeKey.fromJSON(json);
|
|
388
|
+
};
|
|
389
389
|
//# sourceMappingURL=PresentationRpcImpl.js.map
|