@itwin/presentation-backend 5.0.0-dev.56 → 5.0.0-dev.57
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/lib/cjs/presentation-backend/NativePlatform.js +2 -0
- package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.js +8 -2
- package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js +1 -4
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.js +12 -4
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js +6 -0
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +3 -0
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.js +5 -3
- package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetManager.js +2 -1
- package/lib/cjs/presentation-backend/RulesetManager.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js +2 -0
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js.map +1 -1
- package/lib/cjs/presentation-backend/TemporaryStorage.js +29 -25
- package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RulesetVariablesManager.js","sourceRoot":"","sources":["../../../src/presentation-backend/RulesetVariablesManager.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAGH,oEAA+E;AA4E/E;;;GAGG;AACH,MAAa,2BAA2B;IAItC,YAAY,cAA8C,EAAE,SAAiB;QAC3E,IAAI,CAAC,kBAAkB,GAAG,cAAc,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ACpE,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAkB;QAC9B,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,GAAG,CAAW,CAAC;IAC7E,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,UAAkB,EAAE,KAAa;QAC7C,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnE,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,UAAkB;QAC/B,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,QAAQ,CAAa,CAAC;IACpF,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,UAAkB,EAAE,KAAe;QAChD,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,UAAkB;QAC/B,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,IAAI,CAAe,CAAC;IAClF,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,UAAkB,EAAE,KAAiB;QAClD,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpE,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,UAAkB;QAChC,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,SAAS,CAAiB,CAAC;IACzF,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,UAAkB,EAAE,KAAmB;QACrD,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;CACF;AAhJD,kEAgJC","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 { Id64String } from \"@itwin/core-bentley\";\nimport { VariableValue, VariableValueTypes } from \"@itwin/presentation-common\";\nimport { NativePlatformDefinition } from \"./NativePlatform\";\n\n/**\n * Presentation ruleset variables registry.\n * @public\n */\nexport interface RulesetVariablesManager {\n /** Gets a value of the specified type and ID */\n getValue(variableId: string, type: VariableValueTypes): VariableValue;\n /** Sets a value of the specified type */\n setValue(variableId: string, type: VariableValueTypes, value: VariableValue): void;\n /** Unsets variable with given id. */\n unset(variableId: string): void;\n\n /**\n * Retrieves `string` variable value.\n * Returns empty string if variable does not exist or does not convert to string.\n */\n getString(variableId: string): string;\n /**\n * Sets `string` variable value\n */\n setString(variableId: string, value: string): void;\n\n /**\n * Retrieves `boolean` variable value.\n * Returns `false` if variable does not exist or does not convert to boolean.\n */\n getBool(variableId: string): boolean;\n /**\n * Sets `boolean` variable value\n */\n setBool(variableId: string, value: boolean): void;\n\n /**\n * Retrieves `number` variable value.\n * Returns `0` if variable does not exist or does not convert to integer.\n */\n getInt(variableId: string): number;\n /**\n * Sets `number` variable value\n */\n setInt(variableId: string, value: number): void;\n\n /**\n * Retrieves `number[]` variable value.\n * Returns empty array if variable does not exist or does not convert to integer array.\n */\n getInts(variableId: string): number[];\n /**\n * Sets `number[]` variable value\n */\n setInts(variableId: string, value: number[]): void;\n\n /**\n * Retrieves `Id64String` variable value.\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\n */\n getId64(variableId: string): Id64String;\n /**\n * Sets `Id64String` variable value\n */\n setId64(variableId: string, value: Id64String): void;\n\n /**\n * Retrieves `Id64String[]` variable value.\n * Returns empty array if variable does not exist or does not convert to Id64String array.\n */\n getId64s(variableId: string): Id64String[];\n /**\n * Sets `Id64String[]` variable value\n */\n setId64s(variableId: string, value: Id64String[]): void;\n}\n\n/**\n * Presentation ruleset variables registry implementation.\n * @internal\n */\nexport class RulesetVariablesManagerImpl implements RulesetVariablesManager {\n private _getNativePlatform: () => NativePlatformDefinition;\n private _rulesetId: string;\n\n constructor(getNativeAddon: () => NativePlatformDefinition, rulesetId: string) {\n this._getNativePlatform = getNativeAddon;\n this._rulesetId = rulesetId;\n }\n\n public setValueInternal(variableId: string, type: VariableValueTypes, value: VariableValue): void {\n this._getNativePlatform().setRulesetVariableValue(this._rulesetId, variableId, type, value);\n }\n\n public getValueInternal(variableId: string, type: VariableValueTypes): VariableValue {\n return this._getNativePlatform().getRulesetVariableValue(this._rulesetId, variableId, type).result;\n }\n\n public setValue(variableId: string, type: VariableValueTypes, value: VariableValue): void {\n switch (type) {\n case VariableValueTypes.Bool:\n return this.setBool(variableId, value as boolean);\n case VariableValueTypes.Id64:\n return this.setId64(variableId, value as Id64String);\n case VariableValueTypes.Id64Array:\n return this.setId64s(variableId, value as Id64String[]);\n case VariableValueTypes.Int:\n return this.setInt(variableId, value as number);\n case VariableValueTypes.IntArray:\n return this.setInts(variableId, value as number[]);\n case VariableValueTypes.String:\n return this.setString(variableId, value as string);\n }\n }\n\n public unset(variableId: string): void {\n this._getNativePlatform().unsetRulesetVariableValue(this._rulesetId, variableId);\n }\n\n public getValue(variableId: string, type: VariableValueTypes): VariableValue {\n switch (type) {\n case VariableValueTypes.Bool:\n return this.getBool(variableId);\n case VariableValueTypes.Id64:\n return this.getId64(variableId);\n case VariableValueTypes.Id64Array:\n return this.getId64s(variableId);\n case VariableValueTypes.Int:\n return this.getInt(variableId);\n case VariableValueTypes.IntArray:\n return this.getInts(variableId);\n case VariableValueTypes.String:\n return this.getString(variableId);\n }\n }\n\n /**\n * Retrieves `string` variable value.\n * Returns empty string if variable does not exist or does not convert to string.\n */\n public getString(variableId: string): string {\n return this.getValueInternal(variableId, VariableValueTypes.String) as string;\n }\n\n /**\n * Sets `string` variable value\n */\n public setString(variableId: string, value: string): void {\n this.setValueInternal(variableId, VariableValueTypes.String, value);\n }\n\n /**\n * Retrieves `boolean` variable value.\n * Returns `false` if variable does not exist or does not convert to boolean.\n */\n public getBool(variableId: string): boolean {\n return this.getValueInternal(variableId, VariableValueTypes.Bool) as boolean;\n }\n\n /**\n * Sets `boolean` variable value\n */\n public setBool(variableId: string, value: boolean): void {\n this.setValueInternal(variableId, VariableValueTypes.Bool, value);\n }\n\n /**\n * Retrieves `number` variable value.\n * Returns `0` if variable does not exist or does not convert to integer.\n */\n public getInt(variableId: string): number {\n return this.getValueInternal(variableId, VariableValueTypes.Int) as number;\n }\n\n /**\n * Sets `number` variable value\n */\n public setInt(variableId: string, value: number): void {\n this.setValueInternal(variableId, VariableValueTypes.Int, value);\n }\n\n /**\n * Retrieves `number[]` variable value.\n * Returns empty array if variable does not exist or does not convert to integer array.\n */\n public getInts(variableId: string): number[] {\n return this.getValueInternal(variableId, VariableValueTypes.IntArray) as number[];\n }\n\n /**\n * Sets `number[]` variable value\n */\n public setInts(variableId: string, value: number[]): void {\n this.setValueInternal(variableId, VariableValueTypes.IntArray, value);\n }\n\n /**\n * Retrieves `Id64String` variable value.\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\n */\n public getId64(variableId: string): Id64String {\n return this.getValueInternal(variableId, VariableValueTypes.Id64) as Id64String;\n }\n\n /**\n * Sets `Id64String` variable value\n */\n public setId64(variableId: string, value: Id64String): void {\n this.setValueInternal(variableId, VariableValueTypes.Id64, value);\n }\n\n /**\n * Retrieves `Id64String[]` variable value.\n * Returns empty array if variable does not exist or does not convert to Id64String array.\n */\n public getId64s(variableId: string): Id64String[] {\n return this.getValueInternal(variableId, VariableValueTypes.Id64Array) as Id64String[];\n }\n\n /**\n * Sets `Id64String[]` variable value\n */\n public setId64s(variableId: string, value: Id64String[]): void {\n this.setValueInternal(variableId, VariableValueTypes.Id64Array, value);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RulesetVariablesManager.js","sourceRoot":"","sources":["../../../src/presentation-backend/RulesetVariablesManager.ts"],"names":[],"mappings":";AAAA;;;g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AAmB;QACrD,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;CACF;AAhJD,kEAgJC","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 { Id64String } from \"@itwin/core-bentley\";\nimport { VariableValue, VariableValueTypes } from \"@itwin/presentation-common\";\nimport { NativePlatformDefinition } from \"./NativePlatform\";\n\n/**\n * Presentation ruleset variables registry.\n * @public\n */\nexport interface RulesetVariablesManager {\n /** Gets a value of the specified type and ID */\n getValue(variableId: string, type: VariableValueTypes): VariableValue;\n /** Sets a value of the specified type */\n setValue(variableId: string, type: VariableValueTypes, value: VariableValue): void;\n /** Unsets variable with given id. */\n unset(variableId: string): void;\n\n /**\n * Retrieves `string` variable value.\n * Returns empty string if variable does not exist or does not convert to string.\n */\n getString(variableId: string): string;\n /**\n * Sets `string` variable value\n */\n setString(variableId: string, value: string): void;\n\n /**\n * Retrieves `boolean` variable value.\n * Returns `false` if variable does not exist or does not convert to boolean.\n */\n getBool(variableId: string): boolean;\n /**\n * Sets `boolean` variable value\n */\n setBool(variableId: string, value: boolean): void;\n\n /**\n * Retrieves `number` variable value.\n * Returns `0` if variable does not exist or does not convert to integer.\n */\n getInt(variableId: string): number;\n /**\n * Sets `number` variable value\n */\n setInt(variableId: string, value: number): void;\n\n /**\n * Retrieves `number[]` variable value.\n * Returns empty array if variable does not exist or does not convert to integer array.\n */\n getInts(variableId: string): number[];\n /**\n * Sets `number[]` variable value\n */\n setInts(variableId: string, value: number[]): void;\n\n /**\n * Retrieves `Id64String` variable value.\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\n */\n getId64(variableId: string): Id64String;\n /**\n * Sets `Id64String` variable value\n */\n setId64(variableId: string, value: Id64String): void;\n\n /**\n * Retrieves `Id64String[]` variable value.\n * Returns empty array if variable does not exist or does not convert to Id64String array.\n */\n getId64s(variableId: string): Id64String[];\n /**\n * Sets `Id64String[]` variable value\n */\n setId64s(variableId: string, value: Id64String[]): void;\n}\n\n/**\n * Presentation ruleset variables registry implementation.\n * @internal\n */\nexport class RulesetVariablesManagerImpl implements RulesetVariablesManager {\n private _getNativePlatform: () => NativePlatformDefinition;\n private _rulesetId: string;\n\n constructor(getNativeAddon: () => NativePlatformDefinition, rulesetId: string) {\n this._getNativePlatform = getNativeAddon;\n this._rulesetId = rulesetId;\n }\n\n public setValueInternal(variableId: string, type: VariableValueTypes, value: VariableValue): void {\n this._getNativePlatform().setRulesetVariableValue(this._rulesetId, variableId, type, value);\n }\n\n public getValueInternal(variableId: string, type: VariableValueTypes): VariableValue {\n return this._getNativePlatform().getRulesetVariableValue(this._rulesetId, variableId, type).result;\n }\n\n public setValue(variableId: string, type: VariableValueTypes, value: VariableValue): void {\n switch (type) {\n case VariableValueTypes.Bool:\n return this.setBool(variableId, value as boolean);\n case VariableValueTypes.Id64:\n return this.setId64(variableId, value as Id64String);\n case VariableValueTypes.Id64Array:\n return this.setId64s(variableId, value as Id64String[]);\n case VariableValueTypes.Int:\n return this.setInt(variableId, value as number);\n case VariableValueTypes.IntArray:\n return this.setInts(variableId, value as number[]);\n case VariableValueTypes.String:\n return this.setString(variableId, value as string);\n }\n }\n\n public unset(variableId: string): void {\n this._getNativePlatform().unsetRulesetVariableValue(this._rulesetId, variableId);\n }\n\n public getValue(variableId: string, type: VariableValueTypes): VariableValue {\n switch (type) {\n case VariableValueTypes.Bool:\n return this.getBool(variableId);\n case VariableValueTypes.Id64:\n return this.getId64(variableId);\n case VariableValueTypes.Id64Array:\n return this.getId64s(variableId);\n case VariableValueTypes.Int:\n return this.getInt(variableId);\n case VariableValueTypes.IntArray:\n return this.getInts(variableId);\n case VariableValueTypes.String:\n return this.getString(variableId);\n }\n }\n\n /**\n * Retrieves `string` variable value.\n * Returns empty string if variable does not exist or does not convert to string.\n */\n public getString(variableId: string): string {\n return this.getValueInternal(variableId, VariableValueTypes.String) as string;\n }\n\n /**\n * Sets `string` variable value\n */\n public setString(variableId: string, value: string): void {\n this.setValueInternal(variableId, VariableValueTypes.String, value);\n }\n\n /**\n * Retrieves `boolean` variable value.\n * Returns `false` if variable does not exist or does not convert to boolean.\n */\n public getBool(variableId: string): boolean {\n return this.getValueInternal(variableId, VariableValueTypes.Bool) as boolean;\n }\n\n /**\n * Sets `boolean` variable value\n */\n public setBool(variableId: string, value: boolean): void {\n this.setValueInternal(variableId, VariableValueTypes.Bool, value);\n }\n\n /**\n * Retrieves `number` variable value.\n * Returns `0` if variable does not exist or does not convert to integer.\n */\n public getInt(variableId: string): number {\n return this.getValueInternal(variableId, VariableValueTypes.Int) as number;\n }\n\n /**\n * Sets `number` variable value\n */\n public setInt(variableId: string, value: number): void {\n this.setValueInternal(variableId, VariableValueTypes.Int, value);\n }\n\n /**\n * Retrieves `number[]` variable value.\n * Returns empty array if variable does not exist or does not convert to integer array.\n */\n public getInts(variableId: string): number[] {\n return this.getValueInternal(variableId, VariableValueTypes.IntArray) as number[];\n }\n\n /**\n * Sets `number[]` variable value\n */\n public setInts(variableId: string, value: number[]): void {\n this.setValueInternal(variableId, VariableValueTypes.IntArray, value);\n }\n\n /**\n * Retrieves `Id64String` variable value.\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\n */\n public getId64(variableId: string): Id64String {\n return this.getValueInternal(variableId, VariableValueTypes.Id64) as Id64String;\n }\n\n /**\n * Sets `Id64String` variable value\n */\n public setId64(variableId: string, value: Id64String): void {\n this.setValueInternal(variableId, VariableValueTypes.Id64, value);\n }\n\n /**\n * Retrieves `Id64String[]` variable value.\n * Returns empty array if variable does not exist or does not convert to Id64String array.\n */\n public getId64s(variableId: string): Id64String[] {\n return this.getValueInternal(variableId, VariableValueTypes.Id64Array) as Id64String[];\n }\n\n /**\n * Sets `Id64String[]` variable value\n */\n public setId64s(variableId: string, value: Id64String[]): void {\n this.setValueInternal(variableId, VariableValueTypes.Id64Array, value);\n }\n}\n"]}
|
|
@@ -17,35 +17,13 @@ const presentation_common_1 = require("@itwin/presentation-common");
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
class TemporaryStorage {
|
|
20
|
+
_timer;
|
|
21
|
+
_values;
|
|
22
|
+
props;
|
|
20
23
|
/**
|
|
21
24
|
* Constructor. Creates the storage using supplied params.
|
|
22
25
|
*/
|
|
23
26
|
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
|
-
};
|
|
49
27
|
this.props = props;
|
|
50
28
|
this._values = new Map();
|
|
51
29
|
if (this.props.cleanupInterval) {
|
|
@@ -68,6 +46,31 @@ class TemporaryStorage {
|
|
|
68
46
|
this._values.clear();
|
|
69
47
|
this.props.onDisposedAll && this.props.onDisposedAll();
|
|
70
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Cleans up values that are currently outdated (based
|
|
51
|
+
* on their max and unused value lifetimes specified through [[Props]]).
|
|
52
|
+
*/
|
|
53
|
+
disposeOutdatedValues = () => {
|
|
54
|
+
const now = new Date().getTime();
|
|
55
|
+
const valuesToDispose = [];
|
|
56
|
+
for (const [key, entry] of this._values.entries()) {
|
|
57
|
+
if (this.props.maxValueLifetime !== undefined) {
|
|
58
|
+
if (this.props.maxValueLifetime === 0 || now - entry.created.getTime() > this.props.maxValueLifetime) {
|
|
59
|
+
valuesToDispose.push(key);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (this.props.unusedValueLifetime !== undefined) {
|
|
64
|
+
if (this.props.unusedValueLifetime === 0 || now - entry.lastUsed.getTime() > this.props.unusedValueLifetime) {
|
|
65
|
+
valuesToDispose.push(key);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const id of valuesToDispose) {
|
|
71
|
+
this.deleteExistingEntry(id, true);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
71
74
|
deleteExistingEntry(id, isTimeout) {
|
|
72
75
|
(0, core_bentley_1.assert)(this._values.has(id));
|
|
73
76
|
this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id).value, isTimeout ? "timeout" : "request");
|
|
@@ -133,6 +136,7 @@ exports.TemporaryStorage = TemporaryStorage;
|
|
|
133
136
|
* @internal
|
|
134
137
|
*/
|
|
135
138
|
class FactoryBasedTemporaryStorage extends TemporaryStorage {
|
|
139
|
+
props;
|
|
136
140
|
/**
|
|
137
141
|
* Constructor. Creates the storage using supplied params.
|
|
138
142
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemporaryStorage.js","sourceRoot":"","sources":["../../../src/presentation-backend/TemporaryStorage.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAA6C;AAC7C,oEAAmF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,MAAM,GAAG,IAAI,KAAK,EAAK,CAAC;QAC9B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAzHD,4CAyHC;AAWD;;;;;GAKG;AACH,MAAa,4BAAgC,SAAQ,gBAAmB;IAGtE;;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,EAAE,CAAC;YAClB,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,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 } 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 Disposable {\n private _timer?: NodeJS.Timeout;\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 /**\n * Destructor. Must be called to clean up the stored values\n * and other resources\n */\n public [Symbol.dispose]() {\n if (this._timer) {\n clearInterval(this._timer);\n }\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\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 /**\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 }\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 /**\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 }\n return values;\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 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\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;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAA6C;AAC7C,oEAAmF;AAmDnF;;;;;GAKG;AACH,MAAa,gBAAgB;IACnB,MAAM,CAAkB;IACtB,OAAO,CAAiC;IAClC,KAAK,CAA2B;IAEhD;;OAEG;IACH,YAAY,KAA+B;QACzC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;QACpD,IAAI,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACpF,CAAC;IACH,CAA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AK,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,EAAE,CAAC;YAClB,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,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 } 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 Disposable {\n private _timer?: NodeJS.Timeout;\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 /**\n * Destructor. Must be called to clean up the stored values\n * and other resources\n */\n public [Symbol.dispose]() {\n if (this._timer) {\n clearInterval(this._timer);\n }\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\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 /**\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 }\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 /**\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 }\n return values;\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 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\n const value = this.props.factory(id, () => this.notifyValueUsed(id));\n this.addValue(id, value);\n return value;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-backend",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.57",
|
|
4
4
|
"description": "Backend of iTwin.js Presentation library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"main": "lib/cjs/presentation-backend.js",
|
|
24
24
|
"typings": "lib/cjs/presentation-backend",
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@itwin/core-
|
|
27
|
-
"@itwin/
|
|
28
|
-
"@itwin/core-
|
|
29
|
-
"@itwin/core-quantity": "5.0.0-dev.
|
|
30
|
-
"@itwin/
|
|
31
|
-
"@itwin/presentation-common": "5.0.0-dev.
|
|
26
|
+
"@itwin/core-bentley": "5.0.0-dev.57",
|
|
27
|
+
"@itwin/core-backend": "5.0.0-dev.57",
|
|
28
|
+
"@itwin/core-common": "5.0.0-dev.57",
|
|
29
|
+
"@itwin/core-quantity": "5.0.0-dev.57",
|
|
30
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.57",
|
|
31
|
+
"@itwin/presentation-common": "5.0.0-dev.57"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"source-map-support": "^0.5.6",
|
|
68
68
|
"typemoq": "^2.1.0",
|
|
69
69
|
"typescript": "~5.6.2",
|
|
70
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
71
|
-
"@itwin/
|
|
72
|
-
"@itwin/core-
|
|
73
|
-
"@itwin/core-
|
|
74
|
-
"@itwin/
|
|
75
|
-
"@itwin/core-common": "5.0.0-dev.
|
|
76
|
-
"@itwin/
|
|
70
|
+
"@itwin/build-tools": "5.0.0-dev.57",
|
|
71
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.57",
|
|
72
|
+
"@itwin/core-bentley": "5.0.0-dev.57",
|
|
73
|
+
"@itwin/core-backend": "5.0.0-dev.57",
|
|
74
|
+
"@itwin/core-quantity": "5.0.0-dev.57",
|
|
75
|
+
"@itwin/core-common": "5.0.0-dev.57",
|
|
76
|
+
"@itwin/presentation-common": "5.0.0-dev.57"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"object-hash": "^1.3.1",
|