@gooddata/sdk-backend-base 8.13.0-alpha.19 → 8.13.0-alpha.20

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 (157) hide show
  1. package/dist/cachingBackend/index.js +304 -380
  2. package/dist/cachingBackend/index.js.map +1 -1
  3. package/dist/convertors/fromBackend/afm/result.js +3 -3
  4. package/dist/convertors/fromBackend/afm/result.js.map +1 -1
  5. package/dist/customBackend/execution.js +77 -92
  6. package/dist/customBackend/execution.js.map +1 -1
  7. package/dist/customBackend/index.js +78 -114
  8. package/dist/customBackend/index.js.map +1 -1
  9. package/dist/customBackend/workspace.js +39 -40
  10. package/dist/customBackend/workspace.js.map +1 -1
  11. package/dist/decoratedBackend/attributes.js +21 -22
  12. package/dist/decoratedBackend/attributes.js.map +1 -1
  13. package/dist/decoratedBackend/catalog.js +38 -50
  14. package/dist/decoratedBackend/catalog.js.map +1 -1
  15. package/dist/decoratedBackend/dashboards.js +61 -62
  16. package/dist/decoratedBackend/dashboards.js.map +1 -1
  17. package/dist/decoratedBackend/elements.js +47 -70
  18. package/dist/decoratedBackend/elements.js.map +1 -1
  19. package/dist/decoratedBackend/execution.js +62 -79
  20. package/dist/decoratedBackend/execution.js.map +1 -1
  21. package/dist/decoratedBackend/index.js +90 -104
  22. package/dist/decoratedBackend/index.js.map +1 -1
  23. package/dist/decoratedBackend/securitySettings.js +7 -8
  24. package/dist/decoratedBackend/securitySettings.js.map +1 -1
  25. package/dist/decoratedBackend/workspaceSettings.js +12 -26
  26. package/dist/decoratedBackend/workspaceSettings.js.map +1 -1
  27. package/dist/dummyBackend/index.js +347 -391
  28. package/dist/dummyBackend/index.js.map +1 -1
  29. package/dist/eventingBackend/index.js +42 -49
  30. package/dist/eventingBackend/index.js.map +1 -1
  31. package/dist/ldmFactories/builder.js +14 -16
  32. package/dist/ldmFactories/builder.js.map +1 -1
  33. package/dist/ldmFactories/catalog/attributeFactory.js +22 -32
  34. package/dist/ldmFactories/catalog/attributeFactory.js.map +1 -1
  35. package/dist/ldmFactories/catalog/dateDatasetFactory.js +25 -41
  36. package/dist/ldmFactories/catalog/dateDatasetFactory.js.map +1 -1
  37. package/dist/ldmFactories/catalog/factFactory.js +11 -19
  38. package/dist/ldmFactories/catalog/factFactory.js.map +1 -1
  39. package/dist/ldmFactories/catalog/groupFactory.js +14 -27
  40. package/dist/ldmFactories/catalog/groupFactory.js.map +1 -1
  41. package/dist/ldmFactories/catalog/measureFactory.js +15 -25
  42. package/dist/ldmFactories/catalog/measureFactory.js.map +1 -1
  43. package/dist/ldmFactories/dashboard/insightWidgetFactory.js +20 -27
  44. package/dist/ldmFactories/dashboard/insightWidgetFactory.js.map +1 -1
  45. package/dist/ldmFactories/dashboard/kpiWidgetFactory.js +24 -34
  46. package/dist/ldmFactories/dashboard/kpiWidgetFactory.js.map +1 -1
  47. package/dist/ldmFactories/dashboard/widgetFactory.js +20 -39
  48. package/dist/ldmFactories/dashboard/widgetFactory.js.map +1 -1
  49. package/dist/ldmFactories/metadata/attributeFactory.js +13 -21
  50. package/dist/ldmFactories/metadata/attributeFactory.js.map +1 -1
  51. package/dist/ldmFactories/metadata/dashboardFactory.js +7 -15
  52. package/dist/ldmFactories/metadata/dashboardFactory.js.map +1 -1
  53. package/dist/ldmFactories/metadata/dataSetFactory.js +7 -15
  54. package/dist/ldmFactories/metadata/dataSetFactory.js.map +1 -1
  55. package/dist/ldmFactories/metadata/displayFormFactory.js +13 -21
  56. package/dist/ldmFactories/metadata/displayFormFactory.js.map +1 -1
  57. package/dist/ldmFactories/metadata/factFactory.js +7 -15
  58. package/dist/ldmFactories/metadata/factFactory.js.map +1 -1
  59. package/dist/ldmFactories/metadata/factory.js +17 -23
  60. package/dist/ldmFactories/metadata/factory.js.map +1 -1
  61. package/dist/ldmFactories/metadata/measureFactory.js +13 -21
  62. package/dist/ldmFactories/metadata/measureFactory.js.map +1 -1
  63. package/dist/ldmFactories/metadata/variableFactory.js +7 -15
  64. package/dist/ldmFactories/metadata/variableFactory.js.map +1 -1
  65. package/dist/normalizingBackend/index.js +71 -96
  66. package/dist/normalizingBackend/index.js.map +1 -1
  67. package/dist/normalizingBackend/normalizer.js +128 -136
  68. package/dist/normalizingBackend/normalizer.js.map +1 -1
  69. package/dist/toolkit/auth.js +47 -60
  70. package/dist/toolkit/auth.js.map +1 -1
  71. package/dist/toolkit/execution.js +40 -52
  72. package/dist/toolkit/execution.js.map +1 -1
  73. package/dist/toolkit/paging.js +77 -146
  74. package/dist/toolkit/paging.js.map +1 -1
  75. package/dist/toolkit/pluginUrlValidation.js +9 -9
  76. package/dist/toolkit/pluginUrlValidation.js.map +1 -1
  77. package/dist/workspaceSettingsBackend/index.js +23 -46
  78. package/dist/workspaceSettingsBackend/index.js.map +1 -1
  79. package/esm/cachingBackend/index.js +281 -358
  80. package/esm/cachingBackend/index.js.map +1 -1
  81. package/esm/convertors/fromBackend/afm/result.js +3 -3
  82. package/esm/convertors/fromBackend/afm/result.js.map +1 -1
  83. package/esm/customBackend/execution.js +72 -89
  84. package/esm/customBackend/execution.js.map +1 -1
  85. package/esm/customBackend/index.js +75 -112
  86. package/esm/customBackend/index.js.map +1 -1
  87. package/esm/customBackend/workspace.js +37 -39
  88. package/esm/customBackend/workspace.js.map +1 -1
  89. package/esm/decoratedBackend/attributes.js +21 -23
  90. package/esm/decoratedBackend/attributes.js.map +1 -1
  91. package/esm/decoratedBackend/catalog.js +36 -51
  92. package/esm/decoratedBackend/catalog.js.map +1 -1
  93. package/esm/decoratedBackend/dashboards.js +61 -63
  94. package/esm/decoratedBackend/dashboards.js.map +1 -1
  95. package/esm/decoratedBackend/elements.js +47 -73
  96. package/esm/decoratedBackend/elements.js.map +1 -1
  97. package/esm/decoratedBackend/execution.js +60 -81
  98. package/esm/decoratedBackend/execution.js.map +1 -1
  99. package/esm/decoratedBackend/index.js +88 -103
  100. package/esm/decoratedBackend/index.js.map +1 -1
  101. package/esm/decoratedBackend/securitySettings.js +7 -9
  102. package/esm/decoratedBackend/securitySettings.js.map +1 -1
  103. package/esm/decoratedBackend/workspaceSettings.js +12 -27
  104. package/esm/decoratedBackend/workspaceSettings.js.map +1 -1
  105. package/esm/dummyBackend/index.js +342 -387
  106. package/esm/dummyBackend/index.js.map +1 -1
  107. package/esm/eventingBackend/index.js +37 -45
  108. package/esm/eventingBackend/index.js.map +1 -1
  109. package/esm/ldmFactories/builder.js +14 -17
  110. package/esm/ldmFactories/builder.js.map +1 -1
  111. package/esm/ldmFactories/catalog/attributeFactory.js +15 -27
  112. package/esm/ldmFactories/catalog/attributeFactory.js.map +1 -1
  113. package/esm/ldmFactories/catalog/dateDatasetFactory.js +18 -37
  114. package/esm/ldmFactories/catalog/dateDatasetFactory.js.map +1 -1
  115. package/esm/ldmFactories/catalog/factFactory.js +5 -15
  116. package/esm/ldmFactories/catalog/factFactory.js.map +1 -1
  117. package/esm/ldmFactories/catalog/groupFactory.js +11 -27
  118. package/esm/ldmFactories/catalog/groupFactory.js.map +1 -1
  119. package/esm/ldmFactories/catalog/measureFactory.js +9 -21
  120. package/esm/ldmFactories/catalog/measureFactory.js.map +1 -1
  121. package/esm/ldmFactories/dashboard/insightWidgetFactory.js +16 -25
  122. package/esm/ldmFactories/dashboard/insightWidgetFactory.js.map +1 -1
  123. package/esm/ldmFactories/dashboard/kpiWidgetFactory.js +19 -31
  124. package/esm/ldmFactories/dashboard/kpiWidgetFactory.js.map +1 -1
  125. package/esm/ldmFactories/dashboard/widgetFactory.js +19 -39
  126. package/esm/ldmFactories/dashboard/widgetFactory.js.map +1 -1
  127. package/esm/ldmFactories/metadata/attributeFactory.js +9 -19
  128. package/esm/ldmFactories/metadata/attributeFactory.js.map +1 -1
  129. package/esm/ldmFactories/metadata/dashboardFactory.js +3 -13
  130. package/esm/ldmFactories/metadata/dashboardFactory.js.map +1 -1
  131. package/esm/ldmFactories/metadata/dataSetFactory.js +3 -13
  132. package/esm/ldmFactories/metadata/dataSetFactory.js.map +1 -1
  133. package/esm/ldmFactories/metadata/displayFormFactory.js +9 -19
  134. package/esm/ldmFactories/metadata/displayFormFactory.js.map +1 -1
  135. package/esm/ldmFactories/metadata/factFactory.js +3 -13
  136. package/esm/ldmFactories/metadata/factFactory.js.map +1 -1
  137. package/esm/ldmFactories/metadata/factory.js +16 -23
  138. package/esm/ldmFactories/metadata/factory.js.map +1 -1
  139. package/esm/ldmFactories/metadata/measureFactory.js +9 -19
  140. package/esm/ldmFactories/metadata/measureFactory.js.map +1 -1
  141. package/esm/ldmFactories/metadata/variableFactory.js +3 -13
  142. package/esm/ldmFactories/metadata/variableFactory.js.map +1 -1
  143. package/esm/normalizingBackend/index.js +64 -90
  144. package/esm/normalizingBackend/index.js.map +1 -1
  145. package/esm/normalizingBackend/normalizer.js +122 -133
  146. package/esm/normalizingBackend/normalizer.js.map +1 -1
  147. package/esm/toolkit/auth.js +47 -63
  148. package/esm/toolkit/auth.js.map +1 -1
  149. package/esm/toolkit/execution.js +38 -53
  150. package/esm/toolkit/execution.js.map +1 -1
  151. package/esm/toolkit/paging.js +72 -144
  152. package/esm/toolkit/paging.js.map +1 -1
  153. package/esm/toolkit/pluginUrlValidation.js +8 -8
  154. package/esm/toolkit/pluginUrlValidation.js.map +1 -1
  155. package/esm/workspaceSettingsBackend/index.js +19 -43
  156. package/esm/workspaceSettingsBackend/index.js.map +1 -1
  157. package/package.json +7 -6
@@ -1,81 +1,66 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withCaching = exports.RecommendedCachingConfiguration = void 0;
4
- var tslib_1 = require("tslib");
5
- var decoratedBackend_1 = require("../decoratedBackend");
6
- var util_1 = require("@gooddata/util");
7
- var securitySettings_1 = require("../decoratedBackend/securitySettings");
8
- var execution_1 = require("../decoratedBackend/execution");
9
- var catalog_1 = require("../decoratedBackend/catalog");
10
- var elements_1 = require("../decoratedBackend/elements");
11
- var json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
12
- var compact_1 = tslib_1.__importDefault(require("lodash/compact"));
13
- var first_1 = tslib_1.__importDefault(require("lodash/first"));
14
- var flow_1 = tslib_1.__importDefault(require("lodash/flow"));
15
- var identity_1 = tslib_1.__importDefault(require("lodash/identity"));
16
- var ts_invariant_1 = tslib_1.__importDefault(require("ts-invariant"));
17
- var partition_1 = tslib_1.__importDefault(require("lodash/partition"));
18
- var spark_md5_1 = tslib_1.__importDefault(require("spark-md5"));
19
- var sdk_model_1 = require("@gooddata/sdk-model");
20
- var attributes_1 = require("../decoratedBackend/attributes");
21
- var workspaceSettings_1 = require("../decoratedBackend/workspaceSettings");
4
+ const tslib_1 = require("tslib");
5
+ const decoratedBackend_1 = require("../decoratedBackend");
6
+ const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
7
+ const securitySettings_1 = require("../decoratedBackend/securitySettings");
8
+ const execution_1 = require("../decoratedBackend/execution");
9
+ const catalog_1 = require("../decoratedBackend/catalog");
10
+ const elements_1 = require("../decoratedBackend/elements");
11
+ const json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
12
+ const compact_1 = tslib_1.__importDefault(require("lodash/compact"));
13
+ const first_1 = tslib_1.__importDefault(require("lodash/first"));
14
+ const flow_1 = tslib_1.__importDefault(require("lodash/flow"));
15
+ const identity_1 = tslib_1.__importDefault(require("lodash/identity"));
16
+ const ts_invariant_1 = tslib_1.__importDefault(require("ts-invariant"));
17
+ const partition_1 = tslib_1.__importDefault(require("lodash/partition"));
18
+ const spark_md5_1 = tslib_1.__importDefault(require("spark-md5"));
19
+ const sdk_model_1 = require("@gooddata/sdk-model");
20
+ const attributes_1 = require("../decoratedBackend/attributes");
21
+ const workspaceSettings_1 = require("../decoratedBackend/workspaceSettings");
22
22
  //
23
23
  // Execution caching
24
24
  //
25
- var WithExecutionCaching = /** @class */ (function (_super) {
26
- tslib_1.__extends(WithExecutionCaching, _super);
27
- function WithExecutionCaching(decorated, ctx) {
28
- var _this = _super.call(this, decorated) || this;
29
- _this.ctx = ctx;
30
- _this.execute = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
31
- var cacheKey, cache, cacheEntry, result, _a;
32
- var _this = this;
33
- return tslib_1.__generator(this, function (_b) {
34
- switch (_b.label) {
35
- case 0:
36
- cacheKey = this.fingerprint();
37
- cache = this.ctx.caches.execution;
38
- cacheEntry = cache.get(cacheKey);
39
- if (!cacheEntry) {
40
- result = _super.prototype.execute.call(this)
41
- .then(function (res) {
42
- return new WithExecutionResultCaching(res, _this.createNew, _this.ctx);
43
- })
44
- .catch(function (e) {
45
- cache.delete(cacheKey);
46
- throw e;
47
- });
48
- cacheEntry = { result: result };
49
- cache.set(cacheKey, cacheEntry);
50
- }
51
- _a = DefinitionSanitizingExecutionResult.bind;
52
- return [4 /*yield*/, cacheEntry.result];
53
- case 1: return [2 /*return*/, new (_a.apply(DefinitionSanitizingExecutionResult, [void 0, _b.sent(), this.createNew,
54
- this.definition]))()];
55
- }
56
- });
57
- }); };
58
- _this.createNew = function (decorated) {
59
- return new WithExecutionCaching(decorated, _this.ctx);
25
+ class WithExecutionCaching extends execution_1.DecoratedPreparedExecution {
26
+ constructor(decorated, ctx) {
27
+ super(decorated);
28
+ this.ctx = ctx;
29
+ this.execute = async () => {
30
+ const cacheKey = this.fingerprint();
31
+ const cache = this.ctx.caches.execution;
32
+ let cacheEntry = cache.get(cacheKey);
33
+ if (!cacheEntry) {
34
+ const result = super
35
+ .execute()
36
+ .then((res) => {
37
+ return new WithExecutionResultCaching(res, this.createNew, this.ctx);
38
+ })
39
+ .catch((e) => {
40
+ cache.delete(cacheKey);
41
+ throw e;
42
+ });
43
+ cacheEntry = { result };
44
+ cache.set(cacheKey, cacheEntry);
45
+ }
46
+ return new DefinitionSanitizingExecutionResult(await cacheEntry.result, this.createNew, this.definition);
47
+ };
48
+ this.createNew = (decorated) => {
49
+ return new WithExecutionCaching(decorated, this.ctx);
60
50
  };
61
- return _this;
62
51
  }
63
- return WithExecutionCaching;
64
- }(execution_1.DecoratedPreparedExecution));
52
+ }
65
53
  /**
66
54
  * This DataView decorator makes sure that definition used in it is the same as the definition in the result.
67
55
  *
68
56
  * See the usage of this class in {@link DefinitionSanitizingExecutionResult} for more.
69
57
  */
70
- var DefinitionSanitizingDataView = /** @class */ (function (_super) {
71
- tslib_1.__extends(DefinitionSanitizingDataView, _super);
72
- function DefinitionSanitizingDataView(decorated, result) {
73
- var _this = _super.call(this, decorated, result) || this;
74
- _this.definition = result.definition;
75
- return _this;
58
+ class DefinitionSanitizingDataView extends execution_1.DecoratedDataView {
59
+ constructor(decorated, result) {
60
+ super(decorated, result);
61
+ this.definition = result.definition;
76
62
  }
77
- return DefinitionSanitizingDataView;
78
- }(execution_1.DecoratedDataView));
63
+ }
79
64
  /**
80
65
  * This ExecutionResult decorator makes sure that definitions used throughout the result are set
81
66
  * to the definitionOverride provided. This is useful with caching because different definitions may yield
@@ -85,98 +70,75 @@ var DefinitionSanitizingDataView = /** @class */ (function (_super) {
85
70
  *
86
71
  * See the usage of this class in {@link WithExecutionCaching} for more.
87
72
  */
88
- var DefinitionSanitizingExecutionResult = /** @class */ (function (_super) {
89
- tslib_1.__extends(DefinitionSanitizingExecutionResult, _super);
90
- function DefinitionSanitizingExecutionResult(decorated, wrapper, definitionOverride) {
91
- var _this = _super.call(this, decorated, wrapper) || this;
92
- _this.readAll = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
93
- var _a;
94
- return tslib_1.__generator(this, function (_b) {
95
- switch (_b.label) {
96
- case 0:
97
- _a = this.withSanitizedDefinition;
98
- return [4 /*yield*/, _super.prototype.readAll.call(this)];
99
- case 1: return [2 /*return*/, _a.apply(this, [_b.sent()])];
100
- }
101
- });
102
- }); };
103
- _this.readWindow = function (offset, size) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
104
- var _a;
105
- return tslib_1.__generator(this, function (_b) {
106
- switch (_b.label) {
107
- case 0:
108
- _a = this.withSanitizedDefinition;
109
- return [4 /*yield*/, _super.prototype.readWindow.call(this, offset, size)];
110
- case 1: return [2 /*return*/, _a.apply(this, [_b.sent()])];
111
- }
112
- });
113
- }); };
114
- _this.withSanitizedDefinition = function (original) {
115
- return new DefinitionSanitizingDataView(original, _this);
73
+ class DefinitionSanitizingExecutionResult extends execution_1.DecoratedExecutionResult {
74
+ constructor(decorated, wrapper, definitionOverride) {
75
+ super(decorated, wrapper);
76
+ this.readAll = async () => {
77
+ return this.withSanitizedDefinition(await super.readAll());
78
+ };
79
+ this.readWindow = async (offset, size) => {
80
+ return this.withSanitizedDefinition(await super.readWindow(offset, size));
116
81
  };
117
- _this.definition = definitionOverride;
118
- return _this;
82
+ this.withSanitizedDefinition = (original) => {
83
+ return new DefinitionSanitizingDataView(original, this);
84
+ };
85
+ this.definition = definitionOverride;
119
86
  }
120
- return DefinitionSanitizingExecutionResult;
121
- }(execution_1.DecoratedExecutionResult));
87
+ }
122
88
  function windowKey(offset, size) {
123
- return "o(" + offset.join(",") + ")_s(" + size.join(",") + ")";
89
+ return `o(${offset.join(",")})_s(${size.join(",")})`;
124
90
  }
125
- var WithExecutionResultCaching = /** @class */ (function (_super) {
126
- tslib_1.__extends(WithExecutionResultCaching, _super);
127
- function WithExecutionResultCaching(decorated, wrapper, ctx) {
128
- var _this = _super.call(this, decorated, wrapper) || this;
129
- _this.ctx = ctx;
130
- _this.readAll = function () {
131
- if (!_this.allData) {
132
- _this.allData = _super.prototype.readAll.call(_this).catch(function (e) {
133
- _this.allData = undefined;
91
+ class WithExecutionResultCaching extends execution_1.DecoratedExecutionResult {
92
+ constructor(decorated, wrapper, ctx) {
93
+ super(decorated, wrapper);
94
+ this.ctx = ctx;
95
+ this.readAll = () => {
96
+ if (!this.allData) {
97
+ this.allData = super.readAll().catch((e) => {
98
+ this.allData = undefined;
134
99
  throw e;
135
100
  });
136
101
  }
137
- return _this.allData;
102
+ return this.allData;
138
103
  };
139
- _this.readWindow = function (offset, size) {
140
- if (!_this.windows) {
141
- return _super.prototype.readWindow.call(_this, offset, size);
104
+ this.readWindow = (offset, size) => {
105
+ if (!this.windows) {
106
+ return super.readWindow(offset, size);
142
107
  }
143
- var cacheKey = windowKey(offset, size);
144
- var window = _this.windows.get(cacheKey);
108
+ const cacheKey = windowKey(offset, size);
109
+ let window = this.windows.get(cacheKey);
145
110
  if (!window) {
146
- window = _super.prototype.readWindow.call(_this, offset, size).catch(function (e) {
147
- if (_this.windows) {
148
- _this.windows.delete(cacheKey);
111
+ window = super.readWindow(offset, size).catch((e) => {
112
+ if (this.windows) {
113
+ this.windows.delete(cacheKey);
149
114
  }
150
115
  throw e;
151
116
  });
152
- _this.windows.set(cacheKey, window);
117
+ this.windows.set(cacheKey, window);
153
118
  }
154
119
  return window;
155
120
  };
156
- if (cachingEnabled(_this.ctx.config.maxResultWindows)) {
157
- _this.windows = new util_1.LRUCache({ maxSize: _this.ctx.config.maxResultWindows });
121
+ if (cachingEnabled(this.ctx.config.maxResultWindows)) {
122
+ this.windows = new lru_cache_1.default({ max: this.ctx.config.maxResultWindows });
158
123
  }
159
- return _this;
160
124
  }
161
- return WithExecutionResultCaching;
162
- }(execution_1.DecoratedExecutionResult));
125
+ }
163
126
  //
164
127
  // Catalog caching
165
128
  //
166
129
  function optionsKey(options) {
167
130
  return json_stable_stringify_1.default(options);
168
131
  }
169
- var WithCatalogCaching = /** @class */ (function (_super) {
170
- tslib_1.__extends(WithCatalogCaching, _super);
171
- function WithCatalogCaching(decorated, ctx) {
172
- var _this = _super.call(this, decorated) || this;
173
- _this.ctx = ctx;
174
- _this.load = function () {
175
- var cache = _this.getOrCreateWorkspaceEntry(_this.workspace).catalogForOptions;
176
- var cacheKey = optionsKey(_this.options);
177
- var catalog = cache.get(cacheKey);
132
+ class WithCatalogCaching extends catalog_1.DecoratedWorkspaceCatalogFactory {
133
+ constructor(decorated, ctx) {
134
+ super(decorated);
135
+ this.ctx = ctx;
136
+ this.load = () => {
137
+ const cache = this.getOrCreateWorkspaceEntry(this.workspace).catalogForOptions;
138
+ const cacheKey = optionsKey(this.options);
139
+ let catalog = cache.get(cacheKey);
178
140
  if (!catalog) {
179
- catalog = _super.prototype.load.call(_this).catch(function (e) {
141
+ catalog = super.load().catch((e) => {
180
142
  cache.delete(cacheKey);
181
143
  throw e;
182
144
  });
@@ -184,43 +146,40 @@ var WithCatalogCaching = /** @class */ (function (_super) {
184
146
  }
185
147
  return catalog;
186
148
  };
187
- _this.createNew = function (decorated) {
188
- return new WithCatalogCaching(decorated, _this.ctx);
149
+ this.createNew = (decorated) => {
150
+ return new WithCatalogCaching(decorated, this.ctx);
189
151
  };
190
- _this.getOrCreateWorkspaceEntry = function (workspace) {
191
- var cache = _this.ctx.caches.workspaceCatalogs;
192
- var cacheEntry = cache.get(workspace);
152
+ this.getOrCreateWorkspaceEntry = (workspace) => {
153
+ const cache = this.ctx.caches.workspaceCatalogs;
154
+ let cacheEntry = cache.get(workspace);
193
155
  if (!cacheEntry) {
194
156
  cacheEntry = {
195
- catalogForOptions: new util_1.LRUCache({
196
- maxSize: _this.ctx.config.maxCatalogOptions,
157
+ catalogForOptions: new lru_cache_1.default({
158
+ max: this.ctx.config.maxCatalogOptions,
197
159
  }),
198
160
  };
199
161
  cache.set(workspace, cacheEntry);
200
162
  }
201
163
  return cacheEntry;
202
164
  };
203
- return _this;
204
165
  }
205
- return WithCatalogCaching;
206
- }(catalog_1.DecoratedWorkspaceCatalogFactory));
166
+ }
207
167
  //
208
168
  // Organization security settings caching
209
169
  //
210
170
  function validUrlInContextKey(url, context) {
211
- return context + "_" + json_stable_stringify_1.default(url);
171
+ return `${context}_${json_stable_stringify_1.default(url)}`;
212
172
  }
213
- var WithSecuritySettingsCaching = /** @class */ (function (_super) {
214
- tslib_1.__extends(WithSecuritySettingsCaching, _super);
215
- function WithSecuritySettingsCaching(decorated, ctx) {
216
- var _this = _super.call(this, decorated) || this;
217
- _this.ctx = ctx;
218
- _this.isUrlValid = function (url, context) {
219
- var cache = _this.getOrCreateSecuritySettingsEntry(_this.scope).valid;
220
- var cacheKey = validUrlInContextKey(url, context);
221
- var result = cache.get(cacheKey);
173
+ class WithSecuritySettingsCaching extends securitySettings_1.DecoratedSecuritySettingsService {
174
+ constructor(decorated, ctx) {
175
+ super(decorated);
176
+ this.ctx = ctx;
177
+ this.isUrlValid = (url, context) => {
178
+ const cache = this.getOrCreateSecuritySettingsEntry(this.scope).valid;
179
+ const cacheKey = validUrlInContextKey(url, context);
180
+ let result = cache.get(cacheKey);
222
181
  if (!result) {
223
- result = _super.prototype.isUrlValid.call(_this, url, context).catch(function (e) {
182
+ result = super.isUrlValid(url, context).catch((e) => {
224
183
  cache.delete(cacheKey);
225
184
  throw e;
226
185
  });
@@ -228,12 +187,12 @@ var WithSecuritySettingsCaching = /** @class */ (function (_super) {
228
187
  }
229
188
  return result;
230
189
  };
231
- _this.isDashboardPluginUrlValid = function (url, workspace) {
232
- var scope = "plugins_" + workspace;
233
- var cache = _this.getOrCreateSecuritySettingsEntry(scope).valid;
234
- var result = cache.get(url);
190
+ this.isDashboardPluginUrlValid = (url, workspace) => {
191
+ const scope = `plugins_${workspace}`;
192
+ const cache = this.getOrCreateSecuritySettingsEntry(scope).valid;
193
+ let result = cache.get(url);
235
194
  if (!result) {
236
- result = _super.prototype.isDashboardPluginUrlValid.call(_this, url, workspace).catch(function (e) {
195
+ result = super.isDashboardPluginUrlValid(url, workspace).catch((e) => {
237
196
  cache.delete(url);
238
197
  throw e;
239
198
  });
@@ -241,36 +200,33 @@ var WithSecuritySettingsCaching = /** @class */ (function (_super) {
241
200
  }
242
201
  return result;
243
202
  };
244
- _this.getOrCreateSecuritySettingsEntry = function (scope) {
245
- var cache = _this.ctx.caches.securitySettings;
246
- var cacheEntry = cache.get(scope);
203
+ this.getOrCreateSecuritySettingsEntry = (scope) => {
204
+ const cache = this.ctx.caches.securitySettings;
205
+ let cacheEntry = cache.get(scope);
247
206
  if (!cacheEntry) {
248
207
  cacheEntry = {
249
- valid: new util_1.LRUCache({
250
- maxSize: _this.ctx.config.maxSecuritySettingsOrgUrls,
251
- maxAge: _this.ctx.config.maxSecuritySettingsOrgUrlsAge,
208
+ valid: new lru_cache_1.default({
209
+ max: this.ctx.config.maxSecuritySettingsOrgUrls,
210
+ ttl: this.ctx.config.maxSecuritySettingsOrgUrlsAge,
252
211
  }),
253
212
  };
254
213
  cache.set(scope, cacheEntry);
255
214
  }
256
215
  return cacheEntry;
257
216
  };
258
- return _this;
259
217
  }
260
- return WithSecuritySettingsCaching;
261
- }(securitySettings_1.DecoratedSecuritySettingsService));
262
- var WithWorkspaceSettingsCaching = /** @class */ (function (_super) {
263
- tslib_1.__extends(WithWorkspaceSettingsCaching, _super);
264
- function WithWorkspaceSettingsCaching(decorated, ctx, workspace) {
265
- var _this = _super.call(this, decorated) || this;
266
- _this.ctx = ctx;
267
- _this.workspace = workspace;
268
- _this.getSettings = function () {
269
- var cache = _this.getOrCreateWorkspaceEntry(_this.workspace).workspaceSettings;
270
- var cacheKey = _this.workspace;
271
- var workspaceSettings = cache.get(cacheKey);
218
+ }
219
+ class WithWorkspaceSettingsCaching extends workspaceSettings_1.DecoratedWorkspaceSettingsService {
220
+ constructor(decorated, ctx, workspace) {
221
+ super(decorated);
222
+ this.ctx = ctx;
223
+ this.workspace = workspace;
224
+ this.getSettings = () => {
225
+ const cache = this.getOrCreateWorkspaceEntry(this.workspace).workspaceSettings;
226
+ const cacheKey = this.workspace;
227
+ let workspaceSettings = cache.get(cacheKey);
272
228
  if (!workspaceSettings) {
273
- workspaceSettings = _super.prototype.getSettings.call(_this).catch(function (e) {
229
+ workspaceSettings = super.getSettings().catch((e) => {
274
230
  cache.delete(cacheKey);
275
231
  throw e;
276
232
  });
@@ -278,46 +234,40 @@ var WithWorkspaceSettingsCaching = /** @class */ (function (_super) {
278
234
  }
279
235
  return workspaceSettings;
280
236
  };
281
- _this.getOrCreateWorkspaceEntry = function (workspace) {
282
- var cache = _this.ctx.caches.workspaceSettings;
283
- var cacheEntry = cache.get(workspace);
237
+ this.getOrCreateWorkspaceEntry = (workspace) => {
238
+ const cache = this.ctx.caches.workspaceSettings;
239
+ let cacheEntry = cache.get(workspace);
284
240
  if (!cacheEntry) {
285
241
  cacheEntry = {
286
- userWorkspaceSettings: new util_1.LRUCache({
287
- maxSize: _this.ctx.config.maxWorkspaceSettings,
242
+ userWorkspaceSettings: new lru_cache_1.default({
243
+ max: this.ctx.config.maxWorkspaceSettings,
288
244
  }),
289
- workspaceSettings: new util_1.LRUCache({
290
- maxSize: _this.ctx.config.maxWorkspaceSettings,
245
+ workspaceSettings: new lru_cache_1.default({
246
+ max: this.ctx.config.maxWorkspaceSettings,
291
247
  }),
292
248
  };
293
249
  cache.set(workspace, cacheEntry);
294
250
  }
295
251
  return cacheEntry;
296
252
  };
297
- return _this;
298
253
  }
299
- WithWorkspaceSettingsCaching.prototype.getSettingsForCurrentUser = function () {
300
- var cache = this.getOrCreateWorkspaceEntry(this.workspace).userWorkspaceSettings;
301
- var cacheKey = this.workspace; // we assume that the current user does not change over the life span of the backend instance
302
- var userWorkspaceSettings = cache.get(cacheKey);
254
+ getSettingsForCurrentUser() {
255
+ const cache = this.getOrCreateWorkspaceEntry(this.workspace).userWorkspaceSettings;
256
+ const cacheKey = this.workspace; // we assume that the current user does not change over the life span of the backend instance
257
+ let userWorkspaceSettings = cache.get(cacheKey);
303
258
  if (!userWorkspaceSettings) {
304
- userWorkspaceSettings = _super.prototype.getSettingsForCurrentUser.call(this).catch(function (e) {
259
+ userWorkspaceSettings = super.getSettingsForCurrentUser().catch((e) => {
305
260
  cache.delete(cacheKey);
306
261
  throw e;
307
262
  });
308
263
  cache.set(cacheKey, userWorkspaceSettings);
309
264
  }
310
265
  return userWorkspaceSettings;
311
- };
312
- WithWorkspaceSettingsCaching.prototype.setLocale = function (locale) {
313
- return tslib_1.__awaiter(this, void 0, void 0, function () {
314
- return tslib_1.__generator(this, function (_a) {
315
- return [2 /*return*/, _super.prototype.setLocale.call(this, locale)];
316
- });
317
- });
318
- };
319
- return WithWorkspaceSettingsCaching;
320
- }(workspaceSettings_1.DecoratedWorkspaceSettingsService));
266
+ }
267
+ async setLocale(locale) {
268
+ return super.setLocale(locale);
269
+ }
270
+ }
321
271
  //
322
272
  // Attributes caching
323
273
  //
@@ -326,24 +276,24 @@ function refMatchesMdObject(ref, mdObject, type) {
326
276
  sdk_model_1.areObjRefsEqual(ref, sdk_model_1.idRef(mdObject.id, type)) ||
327
277
  sdk_model_1.areObjRefsEqual(ref, sdk_model_1.uriRef(mdObject.uri)));
328
278
  }
329
- var firstDefined = flow_1.default(compact_1.default, first_1.default);
279
+ const firstDefined = flow_1.default(compact_1.default, first_1.default);
330
280
  function elementsCacheKey(ref, settings) {
331
281
  return new spark_md5_1.default().append(sdk_model_1.objRefToString(ref)).append(json_stable_stringify_1.default(settings)).end();
332
282
  }
333
283
  function getOrCreateAttributeCache(ctx, workspace) {
334
- var cache = ctx.caches.workspaceAttributes;
335
- var cacheEntry = cache.get(workspace);
284
+ const cache = ctx.caches.workspaceAttributes;
285
+ let cacheEntry = cache.get(workspace);
336
286
  if (!cacheEntry) {
337
287
  cacheEntry = {
338
- displayForms: new util_1.LRUCache({
339
- maxSize: ctx.config.maxAttributeDisplayFormsPerWorkspace,
288
+ displayForms: new lru_cache_1.default({
289
+ max: ctx.config.maxAttributeDisplayFormsPerWorkspace,
340
290
  }),
341
- attributesByDisplayForms: new util_1.LRUCache({
342
- maxSize: ctx.config.maxAttributesPerWorkspace,
291
+ attributesByDisplayForms: new lru_cache_1.default({
292
+ max: ctx.config.maxAttributesPerWorkspace,
343
293
  }),
344
294
  attributeElementResults: cachingEnabled(ctx.config.maxAttributeElementResultsPerWorkspace)
345
- ? new util_1.LRUCache({
346
- maxSize: ctx.config.maxAttributeElementResultsPerWorkspace,
295
+ ? new lru_cache_1.default({
296
+ max: ctx.config.maxAttributeElementResultsPerWorkspace,
347
297
  })
348
298
  : undefined,
349
299
  };
@@ -351,70 +301,59 @@ function getOrCreateAttributeCache(ctx, workspace) {
351
301
  }
352
302
  return cacheEntry;
353
303
  }
354
- var CachedElementsQuery = /** @class */ (function (_super) {
355
- tslib_1.__extends(CachedElementsQuery, _super);
356
- function CachedElementsQuery(decorated, ctx, workspace, ref, settings) {
357
- if (settings === void 0) { settings = {}; }
358
- var _this = _super.call(this, decorated, settings) || this;
359
- _this.ctx = ctx;
360
- _this.workspace = workspace;
361
- _this.ref = ref;
362
- _this.query = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
363
- var canCache, cache, cacheKey, result;
304
+ class CachedElementsQuery extends elements_1.DecoratedElementsQuery {
305
+ constructor(decorated, ctx, workspace, ref, settings = {}) {
306
+ super(decorated, settings);
307
+ this.ctx = ctx;
308
+ this.workspace = workspace;
309
+ this.ref = ref;
310
+ this.query = async () => {
364
311
  var _a;
365
- return tslib_1.__generator(this, function (_b) {
366
- canCache = !((_a = this.settings.options) === null || _a === void 0 ? void 0 : _a.filter);
367
- if (!canCache) {
368
- return [2 /*return*/, _super.prototype.query.call(this)];
369
- }
370
- cache = getOrCreateAttributeCache(this.ctx, this.workspace).attributeElementResults;
371
- ts_invariant_1.default(cache, "inconsistent attribute element cache config");
372
- cacheKey = elementsCacheKey(this.ref, this.settings);
373
- result = cache.get(cacheKey);
374
- if (!result) {
375
- result = _super.prototype.query.call(this).catch(function (e) {
376
- cache.delete(cacheKey);
377
- throw e;
378
- });
379
- cache.set(cacheKey, result);
380
- }
381
- return [2 /*return*/, result];
382
- });
383
- }); };
384
- return _this;
312
+ const canCache = !((_a = this.settings.options) === null || _a === void 0 ? void 0 : _a.filter);
313
+ if (!canCache) {
314
+ return super.query();
315
+ }
316
+ const cache = getOrCreateAttributeCache(this.ctx, this.workspace).attributeElementResults;
317
+ ts_invariant_1.default(cache, "inconsistent attribute element cache config");
318
+ const cacheKey = elementsCacheKey(this.ref, this.settings);
319
+ let result = cache.get(cacheKey);
320
+ if (!result) {
321
+ result = super.query().catch((e) => {
322
+ cache.delete(cacheKey);
323
+ throw e;
324
+ });
325
+ cache.set(cacheKey, result);
326
+ }
327
+ return result;
328
+ };
385
329
  }
386
- CachedElementsQuery.prototype.createNew = function (decorated, settings) {
330
+ createNew(decorated, settings) {
387
331
  return new CachedElementsQuery(decorated, this.ctx, this.workspace, this.ref, settings);
388
- };
389
- return CachedElementsQuery;
390
- }(elements_1.DecoratedElementsQuery));
391
- var CachedElementsQueryFactory = /** @class */ (function (_super) {
392
- tslib_1.__extends(CachedElementsQueryFactory, _super);
393
- function CachedElementsQueryFactory(decorated, ctx, workspace) {
394
- var _this = _super.call(this, decorated) || this;
395
- _this.ctx = ctx;
396
- _this.workspace = workspace;
397
- return _this;
398
332
  }
399
- CachedElementsQueryFactory.prototype.forDisplayForm = function (ref) {
400
- var decorated = this.decorated.forDisplayForm(ref);
333
+ }
334
+ class CachedElementsQueryFactory extends elements_1.DecoratedElementsQueryFactory {
335
+ constructor(decorated, ctx, workspace) {
336
+ super(decorated);
337
+ this.ctx = ctx;
338
+ this.workspace = workspace;
339
+ }
340
+ forDisplayForm(ref) {
341
+ const decorated = this.decorated.forDisplayForm(ref);
401
342
  return new CachedElementsQuery(decorated, this.ctx, this.workspace, ref);
402
- };
403
- return CachedElementsQueryFactory;
404
- }(elements_1.DecoratedElementsQueryFactory));
405
- var WithAttributesCaching = /** @class */ (function (_super) {
406
- tslib_1.__extends(WithAttributesCaching, _super);
407
- function WithAttributesCaching(decorated, ctx, workspace) {
408
- var _this = _super.call(this, decorated) || this;
409
- _this.ctx = ctx;
410
- _this.workspace = workspace;
411
- _this.getAttributeDisplayForm = function (ref) {
412
- var cache = getOrCreateAttributeCache(_this.ctx, _this.workspace).displayForms;
413
- var idCacheKey = sdk_model_1.isIdentifierRef(ref) ? ref.identifier : undefined;
414
- var uriCacheKey = sdk_model_1.isUriRef(ref) ? ref.uri : undefined;
415
- var cacheItem = firstDefined([idCacheKey, uriCacheKey].map(function (key) { return key && cache.get(key); }));
343
+ }
344
+ }
345
+ class WithAttributesCaching extends attributes_1.DecoratedWorkspaceAttributesService {
346
+ constructor(decorated, ctx, workspace) {
347
+ super(decorated);
348
+ this.ctx = ctx;
349
+ this.workspace = workspace;
350
+ this.getAttributeDisplayForm = (ref) => {
351
+ const cache = getOrCreateAttributeCache(this.ctx, this.workspace).displayForms;
352
+ const idCacheKey = sdk_model_1.isIdentifierRef(ref) ? ref.identifier : undefined;
353
+ const uriCacheKey = sdk_model_1.isUriRef(ref) ? ref.uri : undefined;
354
+ let cacheItem = firstDefined([idCacheKey, uriCacheKey].map((key) => key && cache.get(key)));
416
355
  if (!cacheItem) {
417
- cacheItem = _super.prototype.getAttributeDisplayForm.call(_this, ref).catch(function (e) {
356
+ cacheItem = super.getAttributeDisplayForm(ref).catch((e) => {
418
357
  if (idCacheKey) {
419
358
  cache.delete(idCacheKey);
420
359
  }
@@ -432,136 +371,121 @@ var WithAttributesCaching = /** @class */ (function (_super) {
432
371
  }
433
372
  return cacheItem;
434
373
  };
435
- _this.getAttributeDisplayForms = function (refs) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
436
- var cache, refsWithCacheResults, _a, withCacheHits, withoutCacheHits, refsToLoad, _b, alreadyInCache, loadedFromServer, loadedRefs, outputRefs, candidates;
437
- return tslib_1.__generator(this, function (_c) {
438
- switch (_c.label) {
439
- case 0:
440
- cache = getOrCreateAttributeCache(this.ctx, this.workspace).displayForms;
441
- refsWithCacheResults = refs.map(function (ref) {
442
- var idCacheKey = sdk_model_1.isIdentifierRef(ref) ? ref.identifier : undefined;
443
- var uriCacheKey = sdk_model_1.isUriRef(ref) ? ref.uri : undefined;
444
- var cacheHit = firstDefined([idCacheKey, uriCacheKey].map(function (key) { return key && cache.get(key); }));
445
- return { ref: ref, cacheHit: cacheHit };
446
- });
447
- _a = partition_1.default(refsWithCacheResults, function (_a) {
448
- var cacheHit = _a.cacheHit;
449
- return !!cacheHit;
450
- }), withCacheHits = _a[0], withoutCacheHits = _a[1];
451
- refsToLoad = withoutCacheHits.map(function (item) { return item.ref; });
452
- return [4 /*yield*/, Promise.all([
453
- // await the stuff from cache, we need the data available (we cannot just return the promises)
454
- Promise.all(withCacheHits.map(function (item) { return item.cacheHit; })),
455
- // load items not in cache using the bulk operation
456
- this.decorated.getAttributeDisplayForms(refsToLoad),
457
- ])];
458
- case 1:
459
- _b = _c.sent(), alreadyInCache = _b[0], loadedFromServer = _b[1];
460
- // save newly loaded to cache for future reference
461
- loadedFromServer.forEach(function (loaded) {
462
- var promisifiedResult = Promise.resolve(loaded);
463
- // save the cache item for both types of refs
464
- cache.set(loaded.id, promisifiedResult);
465
- cache.set(loaded.uri, promisifiedResult);
466
- });
467
- loadedRefs = loadedFromServer.map(function (item) { return item.ref; });
468
- outputRefs = this.ctx.capabilities.allowsInconsistentRelations
469
- ? skipMissingReferences(refs, refsToLoad, loadedRefs)
470
- : refs;
471
- candidates = tslib_1.__spreadArrays(loadedFromServer, alreadyInCache);
472
- return [2 /*return*/, outputRefs.map(function (ref) {
473
- var match = candidates.find(function (item) { return refMatchesMdObject(ref, item, "displayForm"); });
474
- // if this bombs, some data got lost in the process
475
- ts_invariant_1.default(match);
476
- return match;
477
- })];
478
- }
374
+ this.getAttributeDisplayForms = async (refs) => {
375
+ const cache = getOrCreateAttributeCache(this.ctx, this.workspace).displayForms;
376
+ // grab a reference to the cache results as soon as possible in case they would get evicted while loading the ones with missing data in cache
377
+ // then would might not be able to call cache.get again and be guaranteed to get the data
378
+ const refsWithCacheResults = refs.map((ref) => {
379
+ const idCacheKey = sdk_model_1.isIdentifierRef(ref) ? ref.identifier : undefined;
380
+ const uriCacheKey = sdk_model_1.isUriRef(ref) ? ref.uri : undefined;
381
+ const cacheHit = firstDefined([idCacheKey, uriCacheKey].map((key) => key && cache.get(key)));
382
+ return { ref, cacheHit };
479
383
  });
480
- }); };
481
- _this.getAttributeByDisplayForm = function (ref) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
482
- var cache, idCacheKey, uriCacheKey, cacheItem;
483
- return tslib_1.__generator(this, function (_a) {
484
- cache = getOrCreateAttributeCache(this.ctx, this.workspace).attributesByDisplayForms;
485
- idCacheKey = sdk_model_1.isIdentifierRef(ref) ? ref.identifier : undefined;
486
- uriCacheKey = sdk_model_1.isUriRef(ref) ? ref.uri : undefined;
487
- cacheItem = firstDefined([idCacheKey, uriCacheKey].map(function (key) { return key && cache.get(key); }));
488
- if (!cacheItem) {
489
- // eslint-disable-next-line sonarjs/no-identical-functions
490
- cacheItem = _super.prototype.getAttributeByDisplayForm.call(this, ref).catch(function (e) {
491
- if (idCacheKey) {
492
- cache.delete(idCacheKey);
493
- }
494
- if (uriCacheKey) {
495
- cache.delete(uriCacheKey);
496
- }
497
- throw e;
498
- });
384
+ const [withCacheHits, withoutCacheHits] = partition_1.default(refsWithCacheResults, ({ cacheHit }) => !!cacheHit);
385
+ const refsToLoad = withoutCacheHits.map((item) => item.ref);
386
+ const [alreadyInCache, loadedFromServer] = await Promise.all([
387
+ // await the stuff from cache, we need the data available (we cannot just return the promises)
388
+ Promise.all(withCacheHits.map((item) => item.cacheHit)),
389
+ // load items not in cache using the bulk operation
390
+ this.decorated.getAttributeDisplayForms(refsToLoad),
391
+ ]);
392
+ // save newly loaded to cache for future reference
393
+ loadedFromServer.forEach((loaded) => {
394
+ const promisifiedResult = Promise.resolve(loaded);
395
+ // save the cache item for both types of refs
396
+ cache.set(loaded.id, promisifiedResult);
397
+ cache.set(loaded.uri, promisifiedResult);
398
+ });
399
+ const loadedRefs = loadedFromServer.map((item) => item.ref);
400
+ const outputRefs = this.ctx.capabilities.allowsInconsistentRelations
401
+ ? skipMissingReferences(refs, refsToLoad, loadedRefs)
402
+ : refs;
403
+ // reconstruct the original ordering
404
+ const candidates = [...loadedFromServer, ...alreadyInCache];
405
+ return outputRefs.map((ref) => {
406
+ const match = candidates.find((item) => refMatchesMdObject(ref, item, "displayForm"));
407
+ // if this bombs, some data got lost in the process
408
+ ts_invariant_1.default(match);
409
+ return match;
410
+ });
411
+ };
412
+ this.getAttributeByDisplayForm = async (ref) => {
413
+ const cache = getOrCreateAttributeCache(this.ctx, this.workspace).attributesByDisplayForms;
414
+ const idCacheKey = sdk_model_1.isIdentifierRef(ref) ? ref.identifier : undefined;
415
+ const uriCacheKey = sdk_model_1.isUriRef(ref) ? ref.uri : undefined;
416
+ let cacheItem = firstDefined([idCacheKey, uriCacheKey].map((key) => key && cache.get(key)));
417
+ if (!cacheItem) {
418
+ // eslint-disable-next-line sonarjs/no-identical-functions
419
+ cacheItem = super.getAttributeByDisplayForm(ref).catch((e) => {
499
420
  if (idCacheKey) {
500
- cache.set(idCacheKey, cacheItem);
421
+ cache.delete(idCacheKey);
501
422
  }
502
423
  if (uriCacheKey) {
503
- cache.set(uriCacheKey, cacheItem);
424
+ cache.delete(uriCacheKey);
504
425
  }
426
+ throw e;
427
+ });
428
+ if (idCacheKey) {
429
+ cache.set(idCacheKey, cacheItem);
505
430
  }
506
- return [2 /*return*/, cacheItem];
507
- });
508
- }); };
509
- return _this;
431
+ if (uriCacheKey) {
432
+ cache.set(uriCacheKey, cacheItem);
433
+ }
434
+ }
435
+ return cacheItem;
436
+ };
510
437
  }
511
- WithAttributesCaching.prototype.elements = function () {
512
- var decorated = this.decorated.elements();
438
+ elements() {
439
+ const decorated = this.decorated.elements();
513
440
  return cachingEnabled(this.ctx.config.maxAttributeElementResultsPerWorkspace)
514
441
  ? new CachedElementsQueryFactory(decorated, this.ctx, this.workspace)
515
442
  : decorated;
516
- };
517
- return WithAttributesCaching;
518
- }(attributes_1.DecoratedWorkspaceAttributesService));
443
+ }
444
+ }
519
445
  //
520
446
  //
521
447
  //
522
448
  function cachedExecutions(ctx) {
523
- return function (original) {
524
- return new execution_1.DecoratedExecutionFactory(original, function (execution) { return new WithExecutionCaching(execution, ctx); });
525
- };
449
+ return (original) => new execution_1.DecoratedExecutionFactory(original, (execution) => new WithExecutionCaching(execution, ctx));
526
450
  }
527
451
  function cachedCatalog(ctx) {
528
- return function (original) { return new WithCatalogCaching(original, ctx); };
452
+ return (original) => new WithCatalogCaching(original, ctx);
529
453
  }
530
454
  function cachedSecuritySettings(ctx) {
531
- return function (original) { return new WithSecuritySettingsCaching(original, ctx); };
455
+ return (original) => new WithSecuritySettingsCaching(original, ctx);
532
456
  }
533
457
  function cachedWorkspaceSettings(ctx) {
534
- return function (original, workspace) { return new WithWorkspaceSettingsCaching(original, ctx, workspace); };
458
+ return (original, workspace) => new WithWorkspaceSettingsCaching(original, ctx, workspace);
535
459
  }
536
460
  function cachedAttributes(ctx) {
537
- return function (original, workspace) { return new WithAttributesCaching(original, ctx, workspace); };
461
+ return (original, workspace) => new WithAttributesCaching(original, ctx, workspace);
538
462
  }
539
463
  function cachingEnabled(desiredSize) {
540
464
  return desiredSize !== undefined && desiredSize > 0;
541
465
  }
542
466
  function cacheControl(ctx) {
543
- var control = {
544
- resetExecutions: function () {
467
+ const control = {
468
+ resetExecutions: () => {
545
469
  var _a;
546
470
  (_a = ctx.caches.execution) === null || _a === void 0 ? void 0 : _a.clear();
547
471
  },
548
- resetCatalogs: function () {
472
+ resetCatalogs: () => {
549
473
  var _a;
550
474
  (_a = ctx.caches.workspaceCatalogs) === null || _a === void 0 ? void 0 : _a.clear();
551
475
  },
552
- resetSecuritySettings: function () {
476
+ resetSecuritySettings: () => {
553
477
  var _a;
554
478
  (_a = ctx.caches.securitySettings) === null || _a === void 0 ? void 0 : _a.clear();
555
479
  },
556
- resetAttributes: function () {
480
+ resetAttributes: () => {
557
481
  var _a;
558
482
  (_a = ctx.caches.workspaceAttributes) === null || _a === void 0 ? void 0 : _a.clear();
559
483
  },
560
- resetWorkspaceSettings: function () {
484
+ resetWorkspaceSettings: () => {
561
485
  var _a;
562
486
  (_a = ctx.caches.workspaceSettings) === null || _a === void 0 ? void 0 : _a.clear();
563
487
  },
564
- resetAll: function () {
488
+ resetAll: () => {
565
489
  control.resetExecutions();
566
490
  control.resetCatalogs();
567
491
  control.resetSecuritySettings();
@@ -572,7 +496,7 @@ function cacheControl(ctx) {
572
496
  return control;
573
497
  }
574
498
  function assertPositiveOrUndefined(value, valueName) {
575
- ts_invariant_1.default(value === undefined || value > 0, valueName + " to cache must be positive or undefined, got: " + value);
499
+ ts_invariant_1.default(value === undefined || value > 0, `${valueName} to cache must be positive or undefined, got: ${value}`);
576
500
  }
577
501
  /**
578
502
  * These are the recommended settings for the backend caching.
@@ -609,47 +533,47 @@ function withCaching(realBackend, config) {
609
533
  assertPositiveOrUndefined(config.maxCatalogOptions, "maxCatalogOptions");
610
534
  assertPositiveOrUndefined(config.maxSecuritySettingsOrgUrls, "maxSecuritySettingsOrgUrls");
611
535
  assertPositiveOrUndefined(config.maxSecuritySettingsOrgUrlsAge, "maxSecuritySettingsOrgUrlsAge");
612
- var execCaching = cachingEnabled(config.maxExecutions);
613
- var catalogCaching = cachingEnabled(config.maxCatalogs);
614
- var securitySettingsCaching = cachingEnabled(config.maxSecuritySettingsOrgs);
615
- var attributeCaching = cachingEnabled(config.maxAttributeWorkspaces);
616
- var workspaceSettingsCaching = cachingEnabled(config.maxWorkspaceSettings);
617
- var ctx = {
536
+ const execCaching = cachingEnabled(config.maxExecutions);
537
+ const catalogCaching = cachingEnabled(config.maxCatalogs);
538
+ const securitySettingsCaching = cachingEnabled(config.maxSecuritySettingsOrgs);
539
+ const attributeCaching = cachingEnabled(config.maxAttributeWorkspaces);
540
+ const workspaceSettingsCaching = cachingEnabled(config.maxWorkspaceSettings);
541
+ const ctx = {
618
542
  caches: {
619
- execution: execCaching ? new util_1.LRUCache({ maxSize: config.maxExecutions }) : undefined,
620
- workspaceCatalogs: catalogCaching ? new util_1.LRUCache({ maxSize: config.maxCatalogs }) : undefined,
543
+ execution: execCaching ? new lru_cache_1.default({ max: config.maxExecutions }) : undefined,
544
+ workspaceCatalogs: catalogCaching ? new lru_cache_1.default({ max: config.maxCatalogs }) : undefined,
621
545
  securitySettings: securitySettingsCaching
622
- ? new util_1.LRUCache({ maxSize: config.maxSecuritySettingsOrgs })
546
+ ? new lru_cache_1.default({ max: config.maxSecuritySettingsOrgs })
623
547
  : undefined,
624
548
  workspaceAttributes: attributeCaching
625
- ? new util_1.LRUCache({ maxSize: config.maxAttributeWorkspaces })
549
+ ? new lru_cache_1.default({ max: config.maxAttributeWorkspaces })
626
550
  : undefined,
627
551
  workspaceSettings: workspaceSettingsCaching
628
- ? new util_1.LRUCache({ maxSize: config.maxWorkspaceSettings })
552
+ ? new lru_cache_1.default({ max: config.maxWorkspaceSettings })
629
553
  : undefined,
630
554
  },
631
- config: config,
555
+ config,
632
556
  capabilities: realBackend.capabilities,
633
557
  };
634
- var execution = execCaching ? cachedExecutions(ctx) : identity_1.default;
635
- var catalog = catalogCaching ? cachedCatalog(ctx) : identity_1.default;
636
- var securitySettings = securitySettingsCaching ? cachedSecuritySettings(ctx) : identity_1.default;
637
- var attributes = attributeCaching ? cachedAttributes(ctx) : identity_1.default;
638
- var workspaceSettings = workspaceSettingsCaching ? cachedWorkspaceSettings(ctx) : identity_1.default;
558
+ const execution = execCaching ? cachedExecutions(ctx) : identity_1.default;
559
+ const catalog = catalogCaching ? cachedCatalog(ctx) : identity_1.default;
560
+ const securitySettings = securitySettingsCaching ? cachedSecuritySettings(ctx) : identity_1.default;
561
+ const attributes = attributeCaching ? cachedAttributes(ctx) : identity_1.default;
562
+ const workspaceSettings = workspaceSettingsCaching ? cachedWorkspaceSettings(ctx) : identity_1.default;
639
563
  if (config.onCacheReady) {
640
564
  config.onCacheReady(cacheControl(ctx));
641
565
  }
642
566
  return decoratedBackend_1.decoratedBackend(realBackend, {
643
- execution: execution,
644
- catalog: catalog,
645
- securitySettings: securitySettings,
646
- attributes: attributes,
647
- workspaceSettings: workspaceSettings,
567
+ execution,
568
+ catalog,
569
+ securitySettings,
570
+ attributes,
571
+ workspaceSettings,
648
572
  });
649
573
  }
650
574
  exports.withCaching = withCaching;
651
575
  function skipMissingReferences(requestedRefs, refsToLoad, refsLoadedFromServer) {
652
- var missingRefs = refsToLoad.filter(function (ref) { return !refsLoadedFromServer.some(function (loadedRef) { return sdk_model_1.areObjRefsEqual(loadedRef, ref); }); });
653
- return requestedRefs.filter(function (inputRef) { return !missingRefs.some(function (missingRef) { return sdk_model_1.areObjRefsEqual(missingRef, inputRef); }); });
576
+ const missingRefs = refsToLoad.filter((ref) => !refsLoadedFromServer.some((loadedRef) => sdk_model_1.areObjRefsEqual(loadedRef, ref)));
577
+ return requestedRefs.filter((inputRef) => !missingRefs.some((missingRef) => sdk_model_1.areObjRefsEqual(missingRef, inputRef)));
654
578
  }
655
579
  //# sourceMappingURL=index.js.map