bruce-models 6.6.2 → 6.6.3
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/dist/bruce-models.es5.js +97 -58
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +97 -58
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/api/api.js +1 -0
- package/dist/lib/api/api.js.map +1 -1
- package/dist/lib/bruce-models.js +1 -1
- package/dist/lib/common/cache.js +9 -8
- package/dist/lib/common/cache.js.map +1 -1
- package/dist/lib/common/lru-cache.js +6 -0
- package/dist/lib/common/lru-cache.js.map +1 -1
- package/dist/lib/entity/entity-lod.js +33 -1
- package/dist/lib/entity/entity-lod.js.map +1 -1
- package/dist/types/api/api.d.ts +1 -0
- package/dist/types/bruce-models.d.ts +1 -1
- package/dist/types/common/lru-cache.d.ts +2 -0
- package/dist/types/entity/entity-lod.d.ts +6 -0
- package/package.json +1 -1
package/dist/bruce-models.umd.js
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
(function (ECacheKey) {
|
|
41
41
|
ECacheKey["Id"] = ":";
|
|
42
42
|
ECacheKey["ListId"] = "::";
|
|
43
|
+
ECacheKey["FilterId"] = ":f:";
|
|
43
44
|
ECacheKey["Assembly"] = "assembly";
|
|
44
45
|
ECacheKey["Entity"] = "entity";
|
|
45
46
|
ECacheKey["EntityType"] = "entitytype";
|
|
@@ -155,9 +156,63 @@
|
|
|
155
156
|
Api.PrepReqParams = PrepReqParams;
|
|
156
157
|
})(exports.Api || (exports.Api = {}));
|
|
157
158
|
|
|
159
|
+
/**
|
|
160
|
+
* A simple LRU cache implementation.
|
|
161
|
+
* LRU cache is a cache that evicts the least recently used item when it is full.
|
|
162
|
+
*/
|
|
163
|
+
class LRUCache {
|
|
164
|
+
constructor(capacity) {
|
|
165
|
+
this.capacity = capacity;
|
|
166
|
+
this.cache = new Map();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get a value from the cache.
|
|
170
|
+
* @param key
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
Get(key) {
|
|
174
|
+
const value = this.cache.get(key);
|
|
175
|
+
if (value) {
|
|
176
|
+
this.cache.delete(key);
|
|
177
|
+
this.cache.set(key, value);
|
|
178
|
+
}
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Set a value in the cache.
|
|
183
|
+
* @param key
|
|
184
|
+
* @param value
|
|
185
|
+
*/
|
|
186
|
+
Set(key, value) {
|
|
187
|
+
if (this.capacity <= 0) {
|
|
188
|
+
// Empty cache.
|
|
189
|
+
// Means we were configured to not cache anything.
|
|
190
|
+
this.cache.clear();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
else if (this.cache.size >= this.capacity) {
|
|
194
|
+
const leastRecentlyUsedKey = this.cache.keys().next().value;
|
|
195
|
+
this.cache.delete(leastRecentlyUsedKey);
|
|
196
|
+
}
|
|
197
|
+
this.cache.set(key, value);
|
|
198
|
+
}
|
|
199
|
+
Entries() {
|
|
200
|
+
return this.cache.entries();
|
|
201
|
+
}
|
|
202
|
+
Clear() {
|
|
203
|
+
this.cache.clear();
|
|
204
|
+
}
|
|
205
|
+
Delete(key) {
|
|
206
|
+
return this.cache.delete(key);
|
|
207
|
+
}
|
|
208
|
+
Keys() {
|
|
209
|
+
return this.cache.keys();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
158
213
|
class CacheControl {
|
|
159
214
|
constructor(id) {
|
|
160
|
-
this.memory = new
|
|
215
|
+
this.memory = new LRUCache(20000);
|
|
161
216
|
this.Disabled = false;
|
|
162
217
|
if (!id) {
|
|
163
218
|
id = "default";
|
|
@@ -184,7 +239,7 @@
|
|
|
184
239
|
data,
|
|
185
240
|
expires
|
|
186
241
|
};
|
|
187
|
-
this.memory.
|
|
242
|
+
this.memory.Set(id, record);
|
|
188
243
|
}
|
|
189
244
|
/**
|
|
190
245
|
* Returns the item with the given id.
|
|
@@ -196,7 +251,7 @@
|
|
|
196
251
|
return null;
|
|
197
252
|
}
|
|
198
253
|
id = String(id);
|
|
199
|
-
let record = this.memory.
|
|
254
|
+
let record = this.memory.Get(id);
|
|
200
255
|
if (!record) {
|
|
201
256
|
return {
|
|
202
257
|
data: null,
|
|
@@ -204,7 +259,7 @@
|
|
|
204
259
|
};
|
|
205
260
|
}
|
|
206
261
|
if (record.expires < Date.now()) {
|
|
207
|
-
this.memory.
|
|
262
|
+
this.memory.Delete(id);
|
|
208
263
|
return {
|
|
209
264
|
data: null,
|
|
210
265
|
found: false
|
|
@@ -219,7 +274,7 @@
|
|
|
219
274
|
* Removes all items from the cache.
|
|
220
275
|
*/
|
|
221
276
|
Clear() {
|
|
222
|
-
this.memory.
|
|
277
|
+
this.memory.Clear();
|
|
223
278
|
}
|
|
224
279
|
/**
|
|
225
280
|
* Removes the item with the given id.
|
|
@@ -227,7 +282,7 @@
|
|
|
227
282
|
*/
|
|
228
283
|
Remove(id) {
|
|
229
284
|
id = String(id);
|
|
230
|
-
this.memory.
|
|
285
|
+
this.memory.Delete(id);
|
|
231
286
|
}
|
|
232
287
|
/**
|
|
233
288
|
* Removes all items that match the callback.
|
|
@@ -235,10 +290,10 @@
|
|
|
235
290
|
* @param callback
|
|
236
291
|
*/
|
|
237
292
|
RemoveBy(callback) {
|
|
238
|
-
const memoryKeys = Array.from(this.memory.
|
|
293
|
+
const memoryKeys = Array.from(this.memory.Keys());
|
|
239
294
|
for (const key of memoryKeys) {
|
|
240
295
|
if (callback(key)) {
|
|
241
|
-
this.memory.
|
|
296
|
+
this.memory.Delete(key);
|
|
242
297
|
}
|
|
243
298
|
}
|
|
244
299
|
}
|
|
@@ -6166,54 +6221,6 @@
|
|
|
6166
6221
|
return full;
|
|
6167
6222
|
}
|
|
6168
6223
|
|
|
6169
|
-
/**
|
|
6170
|
-
* A simple LRU cache implementation.
|
|
6171
|
-
* LRU cache is a cache that evicts the least recently used item when it is full.
|
|
6172
|
-
*/
|
|
6173
|
-
class LRUCache {
|
|
6174
|
-
constructor(capacity) {
|
|
6175
|
-
this.capacity = capacity;
|
|
6176
|
-
this.cache = new Map();
|
|
6177
|
-
}
|
|
6178
|
-
/**
|
|
6179
|
-
* Get a value from the cache.
|
|
6180
|
-
* @param key
|
|
6181
|
-
* @returns
|
|
6182
|
-
*/
|
|
6183
|
-
Get(key) {
|
|
6184
|
-
const value = this.cache.get(key);
|
|
6185
|
-
if (value) {
|
|
6186
|
-
this.cache.delete(key);
|
|
6187
|
-
this.cache.set(key, value);
|
|
6188
|
-
}
|
|
6189
|
-
return value;
|
|
6190
|
-
}
|
|
6191
|
-
/**
|
|
6192
|
-
* Set a value in the cache.
|
|
6193
|
-
* @param key
|
|
6194
|
-
* @param value
|
|
6195
|
-
*/
|
|
6196
|
-
Set(key, value) {
|
|
6197
|
-
if (this.capacity <= 0) {
|
|
6198
|
-
// Empty cache.
|
|
6199
|
-
// Means we were configured to not cache anything.
|
|
6200
|
-
this.cache.clear();
|
|
6201
|
-
return;
|
|
6202
|
-
}
|
|
6203
|
-
else if (this.cache.size >= this.capacity) {
|
|
6204
|
-
const leastRecentlyUsedKey = this.cache.keys().next().value;
|
|
6205
|
-
this.cache.delete(leastRecentlyUsedKey);
|
|
6206
|
-
}
|
|
6207
|
-
this.cache.set(key, value);
|
|
6208
|
-
}
|
|
6209
|
-
Entries() {
|
|
6210
|
-
return this.cache.entries();
|
|
6211
|
-
}
|
|
6212
|
-
Clear() {
|
|
6213
|
-
this.cache.clear();
|
|
6214
|
-
}
|
|
6215
|
-
}
|
|
6216
|
-
|
|
6217
6224
|
(function (EntityAttachmentType) {
|
|
6218
6225
|
// Known attachment types.
|
|
6219
6226
|
let EType;
|
|
@@ -6838,7 +6845,18 @@
|
|
|
6838
6845
|
if (!api) {
|
|
6839
6846
|
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
6840
6847
|
}
|
|
6841
|
-
const
|
|
6848
|
+
const cacheKey = GetLodsFilterCacheKey(filter);
|
|
6849
|
+
const cache = api.GetCacheItem(cacheKey, reqParams);
|
|
6850
|
+
if (cache === null || cache === void 0 ? void 0 : cache.found) {
|
|
6851
|
+
return cache.data;
|
|
6852
|
+
}
|
|
6853
|
+
const prom = api.POST("entity/getlods", filter, reqParams);
|
|
6854
|
+
api.SetCacheItem({
|
|
6855
|
+
key: cacheKey,
|
|
6856
|
+
value: prom,
|
|
6857
|
+
req: reqParams
|
|
6858
|
+
});
|
|
6859
|
+
const data = yield prom;
|
|
6842
6860
|
return {
|
|
6843
6861
|
lods: data.Items
|
|
6844
6862
|
};
|
|
@@ -6942,6 +6960,7 @@
|
|
|
6942
6960
|
"ClientFile.ID": params["ClientFile.ID"]
|
|
6943
6961
|
}, exports.Api.PrepReqParams(reqParams));
|
|
6944
6962
|
api.Cache.Remove(GetEntityListKey(entityId));
|
|
6963
|
+
api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.FilterId);
|
|
6945
6964
|
return res;
|
|
6946
6965
|
});
|
|
6947
6966
|
}
|
|
@@ -6967,6 +6986,7 @@
|
|
|
6967
6986
|
Items: [{ "LODCategory.Key": lodCategoryId, "Level": level }]
|
|
6968
6987
|
}, exports.Api.PrepReqParams(reqParams));
|
|
6969
6988
|
api.Cache.Remove(GetEntityListKey(entityId));
|
|
6989
|
+
api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.FilterId);
|
|
6970
6990
|
});
|
|
6971
6991
|
}
|
|
6972
6992
|
EntityLod.Delete = Delete;
|
|
@@ -7013,6 +7033,25 @@
|
|
|
7013
7033
|
return exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.Entity + entityId;
|
|
7014
7034
|
}
|
|
7015
7035
|
EntityLod.GetEntityListKey = GetEntityListKey;
|
|
7036
|
+
/**
|
|
7037
|
+
* Returns cache identifier for a GetLods filter.
|
|
7038
|
+
* @param filter
|
|
7039
|
+
* @returns
|
|
7040
|
+
*/
|
|
7041
|
+
function GetLodsFilterCacheKey(filter) {
|
|
7042
|
+
const filterStr = JSON.stringify({
|
|
7043
|
+
strict: Boolean(filter.strict),
|
|
7044
|
+
externalSources: Boolean(filter.externalSources),
|
|
7045
|
+
items: filter.Items.map(item => ({
|
|
7046
|
+
entityId: item.entityId || "",
|
|
7047
|
+
categoryId: item.categoryId || "",
|
|
7048
|
+
group: item.group || "DEFAULT",
|
|
7049
|
+
level: item.level || 0
|
|
7050
|
+
}))
|
|
7051
|
+
});
|
|
7052
|
+
return exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.FilterId + btoa(filterStr);
|
|
7053
|
+
}
|
|
7054
|
+
EntityLod.GetLodsFilterCacheKey = GetLodsFilterCacheKey;
|
|
7016
7055
|
})(exports.EntityLod || (exports.EntityLod = {}));
|
|
7017
7056
|
|
|
7018
7057
|
(function (EntityLodCategory) {
|
|
@@ -16078,7 +16117,7 @@
|
|
|
16078
16117
|
})(exports.Tracking || (exports.Tracking = {}));
|
|
16079
16118
|
|
|
16080
16119
|
// This is updated with the package.json version on build.
|
|
16081
|
-
const VERSION = "6.6.
|
|
16120
|
+
const VERSION = "6.6.3";
|
|
16082
16121
|
|
|
16083
16122
|
exports.VERSION = VERSION;
|
|
16084
16123
|
exports.AbstractApi = AbstractApi;
|