@itwin/presentation-backend 4.0.0-dev.48 → 4.0.0-dev.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/cjs/assets/primary-presentation-rules/ElementProperties.PresentationRuleSet.json +14 -14
  2. package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +761 -761
  3. package/lib/cjs/assets/supplemental-presentation-rules/Functional.PresentationRuleSet.json +139 -139
  4. package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +41 -41
  5. package/lib/cjs/presentation-backend/BackendLoggerCategory.js +50 -50
  6. package/lib/cjs/presentation-backend/BackendLoggerCategory.js.map +1 -1
  7. package/lib/cjs/presentation-backend/Constants.d.ts +8 -8
  8. package/lib/cjs/presentation-backend/Constants.js +36 -36
  9. package/lib/cjs/presentation-backend/Constants.js.map +1 -1
  10. package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +11 -11
  11. package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +272 -272
  12. package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -1
  13. package/lib/cjs/presentation-backend/NativePlatform.d.ts +87 -87
  14. package/lib/cjs/presentation-backend/NativePlatform.js +140 -140
  15. package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
  16. package/lib/cjs/presentation-backend/Presentation.d.ts +106 -106
  17. package/lib/cjs/presentation-backend/Presentation.js +148 -148
  18. package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
  19. package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +12 -12
  20. package/lib/cjs/presentation-backend/PresentationIpcHandler.js +41 -41
  21. package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -1
  22. package/lib/cjs/presentation-backend/PresentationManager.d.ts +456 -456
  23. package/lib/cjs/presentation-backend/PresentationManager.js +309 -309
  24. package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
  25. package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +61 -61
  26. package/lib/cjs/presentation-backend/PresentationManagerDetail.js +426 -426
  27. package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -1
  28. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +62 -62
  29. package/lib/cjs/presentation-backend/PresentationRpcImpl.js +388 -388
  30. package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
  31. package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +102 -102
  32. package/lib/cjs/presentation-backend/RulesetEmbedder.js +281 -281
  33. package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
  34. package/lib/cjs/presentation-backend/RulesetManager.d.ts +53 -53
  35. package/lib/cjs/presentation-backend/RulesetManager.js +73 -73
  36. package/lib/cjs/presentation-backend/RulesetManager.js.map +1 -1
  37. package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +140 -140
  38. package/lib/cjs/presentation-backend/RulesetVariablesManager.js +129 -129
  39. package/lib/cjs/presentation-backend/RulesetVariablesManager.js.map +1 -1
  40. package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +28 -28
  41. package/lib/cjs/presentation-backend/SelectionScopesHelper.js +226 -226
  42. package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
  43. package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +123 -123
  44. package/lib/cjs/presentation-backend/TemporaryStorage.js +151 -151
  45. package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -1
  46. package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +27 -27
  47. package/lib/cjs/presentation-backend/UpdatesTracker.js +54 -54
  48. package/lib/cjs/presentation-backend/UpdatesTracker.js.map +1 -1
  49. package/lib/cjs/presentation-backend/Utils.d.ts +49 -49
  50. package/lib/cjs/presentation-backend/Utils.js +107 -107
  51. package/lib/cjs/presentation-backend/Utils.js.map +1 -1
  52. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +16 -16
  53. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +51 -51
  54. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -1
  55. package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +21 -21
  56. package/lib/cjs/presentation-backend/domain/RulesetElements.js +38 -38
  57. package/lib/cjs/presentation-backend/domain/RulesetElements.js.map +1 -1
  58. package/lib/cjs/presentation-backend.d.ts +19 -19
  59. package/lib/cjs/presentation-backend.js +35 -35
  60. package/lib/cjs/presentation-backend.js.map +1 -1
  61. package/package.json +12 -12
@@ -1,124 +1,124 @@
1
- /** @packageDocumentation
2
- * @module Core
3
- */
4
- import { IDisposable } from "@itwin/core-bentley";
5
- /**
6
- * Configuration properties for [[TemporaryStorage]].
7
- * @internal
8
- */
9
- export interface TemporaryStorageProps<T> {
10
- /** A method that's called for every value before it's removed from storage */
11
- cleanupHandler?: (id: string, value: T, reason: "timeout" | "dispose" | "request") => void;
12
- onDisposedSingle?: (id: string) => void;
13
- onDisposedAll?: () => void;
14
- /**
15
- * An interval at which the storage attempts to clean up its values.
16
- * When `0` or `undefined` is specified, values are not cleaned up
17
- * automatically and cleanup has to be initiated manually by calling
18
- * [[TemporaryStorage.disposeOutdatedValues]].
19
- */
20
- cleanupInterval?: number;
21
- /**
22
- * Shortest period of time which the value should be kept in storage
23
- * unused before it's cleaned up.
24
- *
25
- * `undefined` means the values may be kept unused in the storage indefinitely.
26
- * `0` means the values are removed from the storage on every cleanup (either manual
27
- * call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled
28
- * by [[cleanupInterval]])).
29
- */
30
- unusedValueLifetime?: number;
31
- /**
32
- * The maximum period of time which the value should be kept in storage
33
- * before it's cleaned up. The time is measured from the moment the value is added
34
- * to the storage.
35
- *
36
- * `undefined` means the values may be kept indefinitely. `0` means they're removed
37
- * up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]]
38
- * or scheduled (controlled by [[cleanupInterval]])).
39
- */
40
- maxValueLifetime?: number;
41
- }
42
- /** Value with know last used time */
43
- interface TemporaryValue<T> {
44
- created: Date;
45
- lastUsed: Date;
46
- value: T;
47
- }
48
- /**
49
- * Storage for values that get removed from it after being unused (not-requested
50
- * for a specified amount of time).
51
- *
52
- * @internal
53
- */
54
- export declare class TemporaryStorage<T> implements IDisposable {
55
- private _timer?;
56
- protected _values: Map<string, TemporaryValue<T>>;
57
- readonly props: TemporaryStorageProps<T>;
58
- /**
59
- * Constructor. Creates the storage using supplied params.
60
- */
61
- constructor(props: TemporaryStorageProps<T>);
62
- /**
63
- * Destructor. Must be called to clean up the stored values
64
- * and other resources
65
- */
66
- dispose(): void;
67
- /**
68
- * Cleans up values that are currently outdated (based
69
- * on their max and unused value lifetimes specified through [[Props]]).
70
- */
71
- disposeOutdatedValues: () => void;
72
- private deleteExistingEntry;
73
- /**
74
- * Get a value from the storage.
75
- *
76
- * **Note:** requesting a value with this method updates it's last used time.
77
- */
78
- getValue(id: string): T | undefined;
79
- notifyValueUsed(id: string): void;
80
- /**
81
- * Adds a value into the storage.
82
- * @throws An error when trying to add a value with ID that's already stored in the storage.
83
- */
84
- addValue(id: string, value: T): void;
85
- /** Deletes a value with given id. */
86
- deleteValue(id: string): void;
87
- /**
88
- * Get all values currently in this storage.
89
- *
90
- * **Note:** requesting values with this method **doesn't**
91
- * update their last used times.
92
- */
93
- get values(): T[];
94
- }
95
- /**
96
- * Configuration properties for [[FactoryBasedTemporaryStorage]].
97
- * @internal
98
- */
99
- export interface FactoryBasedTemporaryStorageProps<T> extends TemporaryStorageProps<T> {
100
- /** A factory method that creates a stored value given it's identifier */
101
- factory: (id: string, onValueUsed: () => void) => T;
102
- }
103
- /**
104
- * Storage for values that get removed from it after being unused (not-requested
105
- * for a specified amount of time).
106
- *
107
- * @internal
108
- */
109
- export declare class FactoryBasedTemporaryStorage<T> extends TemporaryStorage<T> {
110
- readonly props: FactoryBasedTemporaryStorageProps<T>;
111
- /**
112
- * Constructor. Creates the storage using supplied params.
113
- */
114
- constructor(props: FactoryBasedTemporaryStorageProps<T>);
115
- /**
116
- * Get a value from the storage. If the value with the specified id
117
- * doesn't exist, it gets created.
118
- *
119
- * **Note:** requesting a value with this method updates it's last used time.
120
- */
121
- getValue(id: string): T;
122
- }
123
- export {};
1
+ /** @packageDocumentation
2
+ * @module Core
3
+ */
4
+ import { IDisposable } from "@itwin/core-bentley";
5
+ /**
6
+ * Configuration properties for [[TemporaryStorage]].
7
+ * @internal
8
+ */
9
+ export interface TemporaryStorageProps<T> {
10
+ /** A method that's called for every value before it's removed from storage */
11
+ cleanupHandler?: (id: string, value: T, reason: "timeout" | "dispose" | "request") => void;
12
+ onDisposedSingle?: (id: string) => void;
13
+ onDisposedAll?: () => void;
14
+ /**
15
+ * An interval at which the storage attempts to clean up its values.
16
+ * When `0` or `undefined` is specified, values are not cleaned up
17
+ * automatically and cleanup has to be initiated manually by calling
18
+ * [[TemporaryStorage.disposeOutdatedValues]].
19
+ */
20
+ cleanupInterval?: number;
21
+ /**
22
+ * Shortest period of time which the value should be kept in storage
23
+ * unused before it's cleaned up.
24
+ *
25
+ * `undefined` means the values may be kept unused in the storage indefinitely.
26
+ * `0` means the values are removed from the storage on every cleanup (either manual
27
+ * call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled
28
+ * by [[cleanupInterval]])).
29
+ */
30
+ unusedValueLifetime?: number;
31
+ /**
32
+ * The maximum period of time which the value should be kept in storage
33
+ * before it's cleaned up. The time is measured from the moment the value is added
34
+ * to the storage.
35
+ *
36
+ * `undefined` means the values may be kept indefinitely. `0` means they're removed
37
+ * up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]]
38
+ * or scheduled (controlled by [[cleanupInterval]])).
39
+ */
40
+ maxValueLifetime?: number;
41
+ }
42
+ /** Value with know last used time */
43
+ interface TemporaryValue<T> {
44
+ created: Date;
45
+ lastUsed: Date;
46
+ value: T;
47
+ }
48
+ /**
49
+ * Storage for values that get removed from it after being unused (not-requested
50
+ * for a specified amount of time).
51
+ *
52
+ * @internal
53
+ */
54
+ export declare class TemporaryStorage<T> implements IDisposable {
55
+ private _timer?;
56
+ protected _values: Map<string, TemporaryValue<T>>;
57
+ readonly props: TemporaryStorageProps<T>;
58
+ /**
59
+ * Constructor. Creates the storage using supplied params.
60
+ */
61
+ constructor(props: TemporaryStorageProps<T>);
62
+ /**
63
+ * Destructor. Must be called to clean up the stored values
64
+ * and other resources
65
+ */
66
+ dispose(): void;
67
+ /**
68
+ * Cleans up values that are currently outdated (based
69
+ * on their max and unused value lifetimes specified through [[Props]]).
70
+ */
71
+ disposeOutdatedValues: () => void;
72
+ private deleteExistingEntry;
73
+ /**
74
+ * Get a value from the storage.
75
+ *
76
+ * **Note:** requesting a value with this method updates it's last used time.
77
+ */
78
+ getValue(id: string): T | undefined;
79
+ notifyValueUsed(id: string): void;
80
+ /**
81
+ * Adds a value into the storage.
82
+ * @throws An error when trying to add a value with ID that's already stored in the storage.
83
+ */
84
+ addValue(id: string, value: T): void;
85
+ /** Deletes a value with given id. */
86
+ deleteValue(id: string): void;
87
+ /**
88
+ * Get all values currently in this storage.
89
+ *
90
+ * **Note:** requesting values with this method **doesn't**
91
+ * update their last used times.
92
+ */
93
+ get values(): T[];
94
+ }
95
+ /**
96
+ * Configuration properties for [[FactoryBasedTemporaryStorage]].
97
+ * @internal
98
+ */
99
+ export interface FactoryBasedTemporaryStorageProps<T> extends TemporaryStorageProps<T> {
100
+ /** A factory method that creates a stored value given it's identifier */
101
+ factory: (id: string, onValueUsed: () => void) => T;
102
+ }
103
+ /**
104
+ * Storage for values that get removed from it after being unused (not-requested
105
+ * for a specified amount of time).
106
+ *
107
+ * @internal
108
+ */
109
+ export declare class FactoryBasedTemporaryStorage<T> extends TemporaryStorage<T> {
110
+ readonly props: FactoryBasedTemporaryStorageProps<T>;
111
+ /**
112
+ * Constructor. Creates the storage using supplied params.
113
+ */
114
+ constructor(props: FactoryBasedTemporaryStorageProps<T>);
115
+ /**
116
+ * Get a value from the storage. If the value with the specified id
117
+ * doesn't exist, it gets created.
118
+ *
119
+ * **Note:** requesting a value with this method updates it's last used time.
120
+ */
121
+ getValue(id: string): T;
122
+ }
123
+ export {};
124
124
  //# sourceMappingURL=TemporaryStorage.d.ts.map
@@ -1,152 +1,152 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Core
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.FactoryBasedTemporaryStorage = exports.TemporaryStorage = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const presentation_common_1 = require("@itwin/presentation-common");
13
- /**
14
- * Storage for values that get removed from it after being unused (not-requested
15
- * for a specified amount of time).
16
- *
17
- * @internal
18
- */
19
- class TemporaryStorage {
20
- /**
21
- * Constructor. Creates the storage using supplied params.
22
- */
23
- constructor(props) {
24
- /**
25
- * Cleans up values that are currently outdated (based
26
- * on their max and unused value lifetimes specified through [[Props]]).
27
- */
28
- this.disposeOutdatedValues = () => {
29
- const now = (new Date()).getTime();
30
- const valuesToDispose = [];
31
- for (const [key, entry] of this._values.entries()) {
32
- if (this.props.maxValueLifetime !== undefined) {
33
- if (this.props.maxValueLifetime === 0 || (now - entry.created.getTime()) > this.props.maxValueLifetime) {
34
- valuesToDispose.push(key);
35
- continue;
36
- }
37
- }
38
- if (this.props.unusedValueLifetime !== undefined) {
39
- if (this.props.unusedValueLifetime === 0 || (now - entry.lastUsed.getTime()) > this.props.unusedValueLifetime) {
40
- valuesToDispose.push(key);
41
- continue;
42
- }
43
- }
44
- }
45
- for (const id of valuesToDispose)
46
- this.deleteExistingEntry(id, true);
47
- };
48
- this.props = props;
49
- this._values = new Map();
50
- if (this.props.cleanupInterval)
51
- this._timer = setInterval(this.disposeOutdatedValues, this.props.cleanupInterval);
52
- }
53
- /**
54
- * Destructor. Must be called to clean up the stored values
55
- * and other resources
56
- */
57
- dispose() {
58
- if (this._timer)
59
- clearInterval(this._timer);
60
- if (this.props.cleanupHandler) {
61
- this._values.forEach((v, id) => {
62
- this.props.cleanupHandler(id, v.value, "dispose");
63
- });
64
- }
65
- this._values.clear();
66
- this.props.onDisposedAll && this.props.onDisposedAll();
67
- }
68
- deleteExistingEntry(id, isTimeout) {
69
- (0, core_bentley_1.assert)(this._values.has(id));
70
- this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id).value, isTimeout ? "timeout" : "request");
71
- this._values.delete(id);
72
- this.props.onDisposedSingle && this.props.onDisposedSingle(id);
73
- }
74
- /**
75
- * Get a value from the storage.
76
- *
77
- * **Note:** requesting a value with this method updates it's last used time.
78
- */
79
- getValue(id) {
80
- if (this._values.has(id)) {
81
- const v = this._values.get(id);
82
- v.lastUsed = new Date();
83
- return v.value;
84
- }
85
- return undefined;
86
- }
87
- notifyValueUsed(id) {
88
- const entry = this._values.get(id);
89
- // istanbul ignore else
90
- if (entry)
91
- entry.lastUsed = new Date();
92
- }
93
- /**
94
- * Adds a value into the storage.
95
- * @throws An error when trying to add a value with ID that's already stored in the storage.
96
- */
97
- addValue(id, value) {
98
- if (this._values.has(id))
99
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, `A value with given ID "${id}" already exists in this storage.`);
100
- this._values.set(id, { value, created: new Date(), lastUsed: new Date() });
101
- }
102
- /** Deletes a value with given id. */
103
- deleteValue(id) {
104
- // istanbul ignore else
105
- if (this._values.has(id))
106
- this.deleteExistingEntry(id, false);
107
- }
108
- /**
109
- * Get all values currently in this storage.
110
- *
111
- * **Note:** requesting values with this method **doesn't**
112
- * update their last used times.
113
- */
114
- get values() {
115
- const values = new Array();
116
- for (const v of this._values.values())
117
- values.push(v.value);
118
- return values;
119
- }
120
- }
121
- exports.TemporaryStorage = TemporaryStorage;
122
- /**
123
- * Storage for values that get removed from it after being unused (not-requested
124
- * for a specified amount of time).
125
- *
126
- * @internal
127
- */
128
- class FactoryBasedTemporaryStorage extends TemporaryStorage {
129
- /**
130
- * Constructor. Creates the storage using supplied params.
131
- */
132
- constructor(props) {
133
- super(props);
134
- this.props = props;
135
- }
136
- /**
137
- * Get a value from the storage. If the value with the specified id
138
- * doesn't exist, it gets created.
139
- *
140
- * **Note:** requesting a value with this method updates it's last used time.
141
- */
142
- getValue(id) {
143
- const existingValue = super.getValue(id);
144
- if (existingValue)
145
- return existingValue;
146
- const value = this.props.factory(id, () => this.notifyValueUsed(id));
147
- this.addValue(id, value);
148
- return value;
149
- }
150
- }
151
- exports.FactoryBasedTemporaryStorage = FactoryBasedTemporaryStorage;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Core
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FactoryBasedTemporaryStorage = exports.TemporaryStorage = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const presentation_common_1 = require("@itwin/presentation-common");
13
+ /**
14
+ * Storage for values that get removed from it after being unused (not-requested
15
+ * for a specified amount of time).
16
+ *
17
+ * @internal
18
+ */
19
+ class TemporaryStorage {
20
+ /**
21
+ * Constructor. Creates the storage using supplied params.
22
+ */
23
+ constructor(props) {
24
+ /**
25
+ * Cleans up values that are currently outdated (based
26
+ * on their max and unused value lifetimes specified through [[Props]]).
27
+ */
28
+ this.disposeOutdatedValues = () => {
29
+ const now = (new Date()).getTime();
30
+ const valuesToDispose = [];
31
+ for (const [key, entry] of this._values.entries()) {
32
+ if (this.props.maxValueLifetime !== undefined) {
33
+ if (this.props.maxValueLifetime === 0 || (now - entry.created.getTime()) > this.props.maxValueLifetime) {
34
+ valuesToDispose.push(key);
35
+ continue;
36
+ }
37
+ }
38
+ if (this.props.unusedValueLifetime !== undefined) {
39
+ if (this.props.unusedValueLifetime === 0 || (now - entry.lastUsed.getTime()) > this.props.unusedValueLifetime) {
40
+ valuesToDispose.push(key);
41
+ continue;
42
+ }
43
+ }
44
+ }
45
+ for (const id of valuesToDispose)
46
+ this.deleteExistingEntry(id, true);
47
+ };
48
+ this.props = props;
49
+ this._values = new Map();
50
+ if (this.props.cleanupInterval)
51
+ this._timer = setInterval(this.disposeOutdatedValues, this.props.cleanupInterval);
52
+ }
53
+ /**
54
+ * Destructor. Must be called to clean up the stored values
55
+ * and other resources
56
+ */
57
+ dispose() {
58
+ if (this._timer)
59
+ clearInterval(this._timer);
60
+ if (this.props.cleanupHandler) {
61
+ this._values.forEach((v, id) => {
62
+ this.props.cleanupHandler(id, v.value, "dispose");
63
+ });
64
+ }
65
+ this._values.clear();
66
+ this.props.onDisposedAll && this.props.onDisposedAll();
67
+ }
68
+ deleteExistingEntry(id, isTimeout) {
69
+ (0, core_bentley_1.assert)(this._values.has(id));
70
+ this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id).value, isTimeout ? "timeout" : "request");
71
+ this._values.delete(id);
72
+ this.props.onDisposedSingle && this.props.onDisposedSingle(id);
73
+ }
74
+ /**
75
+ * Get a value from the storage.
76
+ *
77
+ * **Note:** requesting a value with this method updates it's last used time.
78
+ */
79
+ getValue(id) {
80
+ if (this._values.has(id)) {
81
+ const v = this._values.get(id);
82
+ v.lastUsed = new Date();
83
+ return v.value;
84
+ }
85
+ return undefined;
86
+ }
87
+ notifyValueUsed(id) {
88
+ const entry = this._values.get(id);
89
+ // istanbul ignore else
90
+ if (entry)
91
+ entry.lastUsed = new Date();
92
+ }
93
+ /**
94
+ * Adds a value into the storage.
95
+ * @throws An error when trying to add a value with ID that's already stored in the storage.
96
+ */
97
+ addValue(id, value) {
98
+ if (this._values.has(id))
99
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, `A value with given ID "${id}" already exists in this storage.`);
100
+ this._values.set(id, { value, created: new Date(), lastUsed: new Date() });
101
+ }
102
+ /** Deletes a value with given id. */
103
+ deleteValue(id) {
104
+ // istanbul ignore else
105
+ if (this._values.has(id))
106
+ this.deleteExistingEntry(id, false);
107
+ }
108
+ /**
109
+ * Get all values currently in this storage.
110
+ *
111
+ * **Note:** requesting values with this method **doesn't**
112
+ * update their last used times.
113
+ */
114
+ get values() {
115
+ const values = new Array();
116
+ for (const v of this._values.values())
117
+ values.push(v.value);
118
+ return values;
119
+ }
120
+ }
121
+ exports.TemporaryStorage = TemporaryStorage;
122
+ /**
123
+ * Storage for values that get removed from it after being unused (not-requested
124
+ * for a specified amount of time).
125
+ *
126
+ * @internal
127
+ */
128
+ class FactoryBasedTemporaryStorage extends TemporaryStorage {
129
+ /**
130
+ * Constructor. Creates the storage using supplied params.
131
+ */
132
+ constructor(props) {
133
+ super(props);
134
+ this.props = props;
135
+ }
136
+ /**
137
+ * Get a value from the storage. If the value with the specified id
138
+ * doesn't exist, it gets created.
139
+ *
140
+ * **Note:** requesting a value with this method updates it's last used time.
141
+ */
142
+ getValue(id) {
143
+ const existingValue = super.getValue(id);
144
+ if (existingValue)
145
+ return existingValue;
146
+ const value = this.props.factory(id, () => this.notifyValueUsed(id));
147
+ this.addValue(id, value);
148
+ return value;
149
+ }
150
+ }
151
+ exports.FactoryBasedTemporaryStorage = FactoryBasedTemporaryStorage;
152
152
  //# sourceMappingURL=TemporaryStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TemporaryStorage.js","sourceRoot":"","sources":["../../../src/presentation-backend/TemporaryStorage.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,oEAAmF;AAmDnF;;;;;GAKG;AACH,MAAa,gBAAgB;IAM3B;;OAEG;IACH,YAAY,KAA+B;QAwB3C;;;WAGG;QACI,0BAAqB,GAAG,GAAG,EAAE;YAClC,MAAM,GAAG,GAAG,CAAC,IAAI,IAA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KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACa,QAAQ,CAAC,EAAU;QACjC,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,aAAa;YACf,OAAO,aAAa,CAAC;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA3BD,oEA2BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Core\n */\n\nimport { assert, IDisposable } from \"@itwin/core-bentley\";\nimport { PresentationError, PresentationStatus } from \"@itwin/presentation-common\";\n\n/**\n * Configuration properties for [[TemporaryStorage]].\n * @internal\n */\nexport interface TemporaryStorageProps<T> {\n /** A method that's called for every value before it's removed from storage */\n cleanupHandler?: (id: string, value: T, reason: \"timeout\" | \"dispose\" | \"request\") => void;\n\n onDisposedSingle?: (id: string) => void;\n onDisposedAll?: () => void;\n\n /**\n * An interval at which the storage attempts to clean up its values.\n * When `0` or `undefined` is specified, values are not cleaned up\n * automatically and cleanup has to be initiated manually by calling\n * [[TemporaryStorage.disposeOutdatedValues]].\n */\n cleanupInterval?: number;\n\n /**\n * Shortest period of time which the value should be kept in storage\n * unused before it's cleaned up.\n *\n * `undefined` means the values may be kept unused in the storage indefinitely.\n * `0` means the values are removed from the storage on every cleanup (either manual\n * call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled\n * by [[cleanupInterval]])).\n */\n unusedValueLifetime?: number;\n\n /**\n * The maximum period of time which the value should be kept in storage\n * before it's cleaned up. The time is measured from the moment the value is added\n * to the storage.\n *\n * `undefined` means the values may be kept indefinitely. `0` means they're removed\n * up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]]\n * or scheduled (controlled by [[cleanupInterval]])).\n */\n maxValueLifetime?: number;\n}\n\n/** Value with know last used time */\ninterface TemporaryValue<T> {\n created: Date;\n lastUsed: Date;\n value: T;\n}\n\n/**\n * Storage for values that get removed from it after being unused (not-requested\n * for a specified amount of time).\n *\n * @internal\n */\nexport class TemporaryStorage<T> implements IDisposable {\n\n private _timer?: NodeJS.Timer;\n protected _values: Map<string, TemporaryValue<T>>;\n public readonly props: TemporaryStorageProps<T>;\n\n /**\n * Constructor. Creates the storage using supplied params.\n */\n constructor(props: TemporaryStorageProps<T>) {\n this.props = props;\n this._values = new Map<string, TemporaryValue<T>>();\n if (this.props.cleanupInterval)\n this._timer = setInterval(this.disposeOutdatedValues, this.props.cleanupInterval);\n }\n\n /**\n * Destructor. Must be called to clean up the stored values\n * and other resources\n */\n public dispose() {\n if (this._timer)\n clearInterval(this._timer);\n\n if (this.props.cleanupHandler) {\n this._values.forEach((v, id) => {\n this.props.cleanupHandler!(id, v.value, \"dispose\");\n });\n }\n this._values.clear();\n this.props.onDisposedAll && this.props.onDisposedAll();\n }\n\n /**\n * Cleans up values that are currently outdated (based\n * on their max and unused value lifetimes specified through [[Props]]).\n */\n public disposeOutdatedValues = () => {\n const now = (new Date()).getTime();\n const valuesToDispose: string[] = [];\n for (const [key, entry] of this._values.entries()) {\n if (this.props.maxValueLifetime !== undefined) {\n if (this.props.maxValueLifetime === 0 || (now - entry.created.getTime()) > this.props.maxValueLifetime) {\n valuesToDispose.push(key);\n continue;\n }\n }\n if (this.props.unusedValueLifetime !== undefined) {\n if (this.props.unusedValueLifetime === 0 || (now - entry.lastUsed.getTime()) > this.props.unusedValueLifetime) {\n valuesToDispose.push(key);\n continue;\n }\n }\n }\n for (const id of valuesToDispose)\n this.deleteExistingEntry(id, true);\n };\n\n private deleteExistingEntry(id: string, isTimeout: boolean) {\n assert(this._values.has(id));\n this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id)!.value, isTimeout ? \"timeout\" : \"request\");\n this._values.delete(id);\n this.props.onDisposedSingle && this.props.onDisposedSingle(id);\n }\n\n /**\n * Get a value from the storage.\n *\n * **Note:** requesting a value with this method updates it's last used time.\n */\n public getValue(id: string): T | undefined {\n if (this._values.has(id)) {\n const v = this._values.get(id)!;\n v.lastUsed = new Date();\n return v.value;\n }\n return undefined;\n }\n\n public notifyValueUsed(id: string) {\n const entry = this._values.get(id);\n // istanbul ignore else\n if (entry)\n entry.lastUsed = new Date();\n }\n\n /**\n * Adds a value into the storage.\n * @throws An error when trying to add a value with ID that's already stored in the storage.\n */\n public addValue(id: string, value: T) {\n if (this._values.has(id))\n throw new PresentationError(PresentationStatus.InvalidArgument, `A value with given ID \"${id}\" already exists in this storage.`);\n this._values.set(id, { value, created: new Date(), lastUsed: new Date() });\n }\n\n /** Deletes a value with given id. */\n public deleteValue(id: string) {\n // istanbul ignore else\n if (this._values.has(id))\n this.deleteExistingEntry(id, false);\n }\n\n /**\n * Get all values currently in this storage.\n *\n * **Note:** requesting values with this method **doesn't**\n * update their last used times.\n */\n public get values(): T[] {\n const values = new Array<T>();\n for (const v of this._values.values())\n values.push(v.value);\n return values;\n }\n\n}\n\n/**\n * Configuration properties for [[FactoryBasedTemporaryStorage]].\n * @internal\n */\nexport interface FactoryBasedTemporaryStorageProps<T> extends TemporaryStorageProps<T> {\n /** A factory method that creates a stored value given it's identifier */\n factory: (id: string, onValueUsed: () => void) => T;\n}\n\n/**\n * Storage for values that get removed from it after being unused (not-requested\n * for a specified amount of time).\n *\n * @internal\n */\nexport class FactoryBasedTemporaryStorage<T> extends TemporaryStorage<T> {\n\n public override readonly props: FactoryBasedTemporaryStorageProps<T>;\n\n /**\n * Constructor. Creates the storage using supplied params.\n */\n constructor(props: FactoryBasedTemporaryStorageProps<T>) {\n super(props);\n this.props = props;\n }\n\n /**\n * Get a value from the storage. If the value with the specified id\n * doesn't exist, it gets created.\n *\n * **Note:** requesting a value with this method updates it's last used time.\n */\n public override getValue(id: string): T {\n const existingValue = super.getValue(id);\n if (existingValue)\n return existingValue;\n\n const value = this.props.factory(id, () => this.notifyValueUsed(id));\n this.addValue(id, value);\n return value;\n }\n}\n"]}
1
+ {"version":3,"file":"TemporaryStorage.js","sourceRoot":"","sources":["../../../src/presentation-backend/TemporaryStorage.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,oEAAmF;AAmDnF;;;;;GAKG;AACH,MAAa,gBAAgB;IAM3B;;OAEG;IACH,YAAY,KAA+B;QAwB3C;;;WAGG;QACI,0BAAqB,GAAG,GAAG,EAAE;YAClC,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YACnC,MAAM,eAAe,GAAa,EAAE,CAAC;YACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE;gBACjD,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAAE;oBAC7C,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;wBACtG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;wBAC1B,SAAS;qBACV;iBACF;gBACD,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,KAAK,SAAS,EAAE;oBAChD,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB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AAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,IAAW,MAAM;QACf,MAAM,MAAM,GAAG,IAAI,KAAK,EAAK,CAAC;QAC9B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACnC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;CAEF;AApHD,4CAoHC;AAWD;;;;;GAKG;AACH,MAAa,4BAAgC,SAAQ,gBAAmB;IAItE;;OAEG;IACH,YAAY,KAA2C;QACrD,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACa,QAAQ,CAAC,EAAU;QACjC,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,aAAa;YACf,OAAO,aAAa,CAAC;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA3BD,oEA2BC","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 { assert, IDisposable } from \"@itwin/core-bentley\";\r\nimport { PresentationError, PresentationStatus } from \"@itwin/presentation-common\";\r\n\r\n/**\r\n * Configuration properties for [[TemporaryStorage]].\r\n * @internal\r\n */\r\nexport interface TemporaryStorageProps<T> {\r\n /** A method that's called for every value before it's removed from storage */\r\n cleanupHandler?: (id: string, value: T, reason: \"timeout\" | \"dispose\" | \"request\") => void;\r\n\r\n onDisposedSingle?: (id: string) => void;\r\n onDisposedAll?: () => void;\r\n\r\n /**\r\n * An interval at which the storage attempts to clean up its values.\r\n * When `0` or `undefined` is specified, values are not cleaned up\r\n * automatically and cleanup has to be initiated manually by calling\r\n * [[TemporaryStorage.disposeOutdatedValues]].\r\n */\r\n cleanupInterval?: number;\r\n\r\n /**\r\n * Shortest period of time which the value should be kept in storage\r\n * unused before it's cleaned up.\r\n *\r\n * `undefined` means the values may be kept unused in the storage indefinitely.\r\n * `0` means the values are removed from the storage on every cleanup (either manual\r\n * call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled\r\n * by [[cleanupInterval]])).\r\n */\r\n unusedValueLifetime?: number;\r\n\r\n /**\r\n * The maximum period of time which the value should be kept in storage\r\n * before it's cleaned up. The time is measured from the moment the value is added\r\n * to the storage.\r\n *\r\n * `undefined` means the values may be kept indefinitely. `0` means they're removed\r\n * up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]]\r\n * or scheduled (controlled by [[cleanupInterval]])).\r\n */\r\n maxValueLifetime?: number;\r\n}\r\n\r\n/** Value with know last used time */\r\ninterface TemporaryValue<T> {\r\n created: Date;\r\n lastUsed: Date;\r\n value: T;\r\n}\r\n\r\n/**\r\n * Storage for values that get removed from it after being unused (not-requested\r\n * for a specified amount of time).\r\n *\r\n * @internal\r\n */\r\nexport class TemporaryStorage<T> implements IDisposable {\r\n\r\n private _timer?: NodeJS.Timer;\r\n protected _values: Map<string, TemporaryValue<T>>;\r\n public readonly props: TemporaryStorageProps<T>;\r\n\r\n /**\r\n * Constructor. Creates the storage using supplied params.\r\n */\r\n constructor(props: TemporaryStorageProps<T>) {\r\n this.props = props;\r\n this._values = new Map<string, TemporaryValue<T>>();\r\n if (this.props.cleanupInterval)\r\n this._timer = setInterval(this.disposeOutdatedValues, this.props.cleanupInterval);\r\n }\r\n\r\n /**\r\n * Destructor. Must be called to clean up the stored values\r\n * and other resources\r\n */\r\n public dispose() {\r\n if (this._timer)\r\n clearInterval(this._timer);\r\n\r\n if (this.props.cleanupHandler) {\r\n this._values.forEach((v, id) => {\r\n this.props.cleanupHandler!(id, v.value, \"dispose\");\r\n });\r\n }\r\n this._values.clear();\r\n this.props.onDisposedAll && this.props.onDisposedAll();\r\n }\r\n\r\n /**\r\n * Cleans up values that are currently outdated (based\r\n * on their max and unused value lifetimes specified through [[Props]]).\r\n */\r\n public disposeOutdatedValues = () => {\r\n const now = (new Date()).getTime();\r\n const valuesToDispose: string[] = [];\r\n for (const [key, entry] of this._values.entries()) {\r\n if (this.props.maxValueLifetime !== undefined) {\r\n if (this.props.maxValueLifetime === 0 || (now - entry.created.getTime()) > this.props.maxValueLifetime) {\r\n valuesToDispose.push(key);\r\n continue;\r\n }\r\n }\r\n if (this.props.unusedValueLifetime !== undefined) {\r\n if (this.props.unusedValueLifetime === 0 || (now - entry.lastUsed.getTime()) > this.props.unusedValueLifetime) {\r\n valuesToDispose.push(key);\r\n continue;\r\n }\r\n }\r\n }\r\n for (const id of valuesToDispose)\r\n this.deleteExistingEntry(id, true);\r\n };\r\n\r\n private deleteExistingEntry(id: string, isTimeout: boolean) {\r\n assert(this._values.has(id));\r\n this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id)!.value, isTimeout ? \"timeout\" : \"request\");\r\n this._values.delete(id);\r\n this.props.onDisposedSingle && this.props.onDisposedSingle(id);\r\n }\r\n\r\n /**\r\n * Get a value from the storage.\r\n *\r\n * **Note:** requesting a value with this method updates it's last used time.\r\n */\r\n public getValue(id: string): T | undefined {\r\n if (this._values.has(id)) {\r\n const v = this._values.get(id)!;\r\n v.lastUsed = new Date();\r\n return v.value;\r\n }\r\n return undefined;\r\n }\r\n\r\n public notifyValueUsed(id: string) {\r\n const entry = this._values.get(id);\r\n // istanbul ignore else\r\n if (entry)\r\n entry.lastUsed = new Date();\r\n }\r\n\r\n /**\r\n * Adds a value into the storage.\r\n * @throws An error when trying to add a value with ID that's already stored in the storage.\r\n */\r\n public addValue(id: string, value: T) {\r\n if (this._values.has(id))\r\n throw new PresentationError(PresentationStatus.InvalidArgument, `A value with given ID \"${id}\" already exists in this storage.`);\r\n this._values.set(id, { value, created: new Date(), lastUsed: new Date() });\r\n }\r\n\r\n /** Deletes a value with given id. */\r\n public deleteValue(id: string) {\r\n // istanbul ignore else\r\n if (this._values.has(id))\r\n this.deleteExistingEntry(id, false);\r\n }\r\n\r\n /**\r\n * Get all values currently in this storage.\r\n *\r\n * **Note:** requesting values with this method **doesn't**\r\n * update their last used times.\r\n */\r\n public get values(): T[] {\r\n const values = new Array<T>();\r\n for (const v of this._values.values())\r\n values.push(v.value);\r\n return values;\r\n }\r\n\r\n}\r\n\r\n/**\r\n * Configuration properties for [[FactoryBasedTemporaryStorage]].\r\n * @internal\r\n */\r\nexport interface FactoryBasedTemporaryStorageProps<T> extends TemporaryStorageProps<T> {\r\n /** A factory method that creates a stored value given it's identifier */\r\n factory: (id: string, onValueUsed: () => void) => T;\r\n}\r\n\r\n/**\r\n * Storage for values that get removed from it after being unused (not-requested\r\n * for a specified amount of time).\r\n *\r\n * @internal\r\n */\r\nexport class FactoryBasedTemporaryStorage<T> extends TemporaryStorage<T> {\r\n\r\n public override readonly props: FactoryBasedTemporaryStorageProps<T>;\r\n\r\n /**\r\n * Constructor. Creates the storage using supplied params.\r\n */\r\n constructor(props: FactoryBasedTemporaryStorageProps<T>) {\r\n super(props);\r\n this.props = props;\r\n }\r\n\r\n /**\r\n * Get a value from the storage. If the value with the specified id\r\n * doesn't exist, it gets created.\r\n *\r\n * **Note:** requesting a value with this method updates it's last used time.\r\n */\r\n public override getValue(id: string): T {\r\n const existingValue = super.getValue(id);\r\n if (existingValue)\r\n return existingValue;\r\n\r\n const value = this.props.factory(id, () => this.notifyValueUsed(id));\r\n this.addValue(id, value);\r\n return value;\r\n }\r\n}\r\n"]}