bruce-models 6.6.2 → 6.6.4
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 +107 -61
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +107 -61
- 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 +43 -4
- 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,10 +6845,28 @@
|
|
|
6838
6845
|
if (!api) {
|
|
6839
6846
|
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
6840
6847
|
}
|
|
6841
|
-
const
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
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 yield cache.data;
|
|
6852
|
+
}
|
|
6853
|
+
const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
|
|
6854
|
+
try {
|
|
6855
|
+
const data = yield api.POST("entity/getlods", filter, reqParams);
|
|
6856
|
+
res({
|
|
6857
|
+
lods: data.Items || []
|
|
6858
|
+
});
|
|
6859
|
+
}
|
|
6860
|
+
catch (e) {
|
|
6861
|
+
rej(e);
|
|
6862
|
+
}
|
|
6863
|
+
}));
|
|
6864
|
+
api.SetCacheItem({
|
|
6865
|
+
key: cacheKey,
|
|
6866
|
+
value: prom,
|
|
6867
|
+
req: reqParams
|
|
6868
|
+
});
|
|
6869
|
+
return yield prom;
|
|
6845
6870
|
});
|
|
6846
6871
|
}
|
|
6847
6872
|
EntityLod.GetLods = GetLods;
|
|
@@ -6942,6 +6967,7 @@
|
|
|
6942
6967
|
"ClientFile.ID": params["ClientFile.ID"]
|
|
6943
6968
|
}, exports.Api.PrepReqParams(reqParams));
|
|
6944
6969
|
api.Cache.Remove(GetEntityListKey(entityId));
|
|
6970
|
+
api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.FilterId);
|
|
6945
6971
|
return res;
|
|
6946
6972
|
});
|
|
6947
6973
|
}
|
|
@@ -6967,6 +6993,7 @@
|
|
|
6967
6993
|
Items: [{ "LODCategory.Key": lodCategoryId, "Level": level }]
|
|
6968
6994
|
}, exports.Api.PrepReqParams(reqParams));
|
|
6969
6995
|
api.Cache.Remove(GetEntityListKey(entityId));
|
|
6996
|
+
api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.FilterId);
|
|
6970
6997
|
});
|
|
6971
6998
|
}
|
|
6972
6999
|
EntityLod.Delete = Delete;
|
|
@@ -7013,6 +7040,25 @@
|
|
|
7013
7040
|
return exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.Entity + entityId;
|
|
7014
7041
|
}
|
|
7015
7042
|
EntityLod.GetEntityListKey = GetEntityListKey;
|
|
7043
|
+
/**
|
|
7044
|
+
* Returns cache identifier for a GetLods filter.
|
|
7045
|
+
* @param filter
|
|
7046
|
+
* @returns
|
|
7047
|
+
*/
|
|
7048
|
+
function GetLodsFilterCacheKey(filter) {
|
|
7049
|
+
const filterStr = JSON.stringify({
|
|
7050
|
+
strict: Boolean(filter.strict),
|
|
7051
|
+
externalSources: Boolean(filter.externalSources),
|
|
7052
|
+
items: filter.Items.map(item => ({
|
|
7053
|
+
entityId: item.entityId || "",
|
|
7054
|
+
categoryId: item.categoryId || "",
|
|
7055
|
+
group: item.group || "DEFAULT",
|
|
7056
|
+
level: item.level || 0
|
|
7057
|
+
}))
|
|
7058
|
+
});
|
|
7059
|
+
return exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.FilterId + btoa(filterStr);
|
|
7060
|
+
}
|
|
7061
|
+
EntityLod.GetLodsFilterCacheKey = GetLodsFilterCacheKey;
|
|
7016
7062
|
})(exports.EntityLod || (exports.EntityLod = {}));
|
|
7017
7063
|
|
|
7018
7064
|
(function (EntityLodCategory) {
|
|
@@ -16078,7 +16124,7 @@
|
|
|
16078
16124
|
})(exports.Tracking || (exports.Tracking = {}));
|
|
16079
16125
|
|
|
16080
16126
|
// This is updated with the package.json version on build.
|
|
16081
|
-
const VERSION = "6.6.
|
|
16127
|
+
const VERSION = "6.6.4";
|
|
16082
16128
|
|
|
16083
16129
|
exports.VERSION = VERSION;
|
|
16084
16130
|
exports.AbstractApi = AbstractApi;
|