bruce-models 3.9.2 → 3.9.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.
@@ -78,6 +78,8 @@
78
78
  ECacheKey["Plugin"] = "plugin";
79
79
  ECacheKey["PluginIndexFile"] = "pluginindexfile";
80
80
  ECacheKey["EntityHistoricData"] = "entityhistoricdata";
81
+ ECacheKey["EntityHistoricDataRec"] = "entityhistoricdatarec";
82
+ ECacheKey["EntityHistoricDataStats"] = "entityhistoricdatastats";
81
83
  })(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
82
84
  // 1 minute.
83
85
  Api.DEFAULT_CACHE_DURATION = 60 * 1000;
@@ -244,6 +246,13 @@
244
246
  RemoveByContains(text) {
245
247
  this.RemoveBy(key => String(key).includes(String(text)));
246
248
  }
249
+ /**
250
+ * Removes items based on a callback's response.
251
+ * @param callback
252
+ */
253
+ RemoveByCallback(callback) {
254
+ this.RemoveBy(callback);
255
+ }
247
256
  }
248
257
 
249
258
  // TODO: Currently checks for CSV vs json specifically,
@@ -2994,6 +3003,197 @@
2994
3003
  })(EDisplayType = ZoomControl.EDisplayType || (ZoomControl.EDisplayType = {}));
2995
3004
  })(exports.ZoomControl || (exports.ZoomControl = {}));
2996
3005
 
3006
+ (function (EntityHistoricData) {
3007
+ /**
3008
+ * Returns historic data for an array of Entity IDs.
3009
+ * A maximum number of records will be returned per Entity ID, this information is returned in the response.
3010
+ * @param params
3011
+ * @returns
3012
+ */
3013
+ function GetList(params) {
3014
+ return __awaiter(this, void 0, void 0, function* () {
3015
+ let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
3016
+ // Save time and just return a none response if no entity IDs are provided.
3017
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3018
+ return {
3019
+ limitPerEntity: 0,
3020
+ recordsByIds: {}
3021
+ };
3022
+ }
3023
+ if (!api) {
3024
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
3025
+ }
3026
+ if (typeof attrKey != "string") {
3027
+ attrKey = exports.PathUtils.Wrap(attrKey);
3028
+ }
3029
+ const cacheKey = GetListCacheKey(entityIds, attrKey, dateTimeFrom, dateTimeTo);
3030
+ const cached = api.GetCacheItem(cacheKey, req);
3031
+ if (cached === null || cached === void 0 ? void 0 : cached.found) {
3032
+ return cached.data;
3033
+ }
3034
+ const urlParams = new URLSearchParams();
3035
+ for (const entityId of entityIds) {
3036
+ urlParams.append("entityId", entityId);
3037
+ }
3038
+ urlParams.append("attrKey", attrKey);
3039
+ urlParams.append("dateTimeFrom", dateTimeFrom);
3040
+ urlParams.append("dateTimeTo", dateTimeTo);
3041
+ const prom = api.GET(`v1/entity/historicData?${urlParams.toString()}`, exports.Api.PrepReqParams(req));
3042
+ api.SetCacheItem({
3043
+ key: cacheKey,
3044
+ value: prom,
3045
+ req: req,
3046
+ // Short cache. 30 seconds.
3047
+ duration: 30000
3048
+ });
3049
+ return prom;
3050
+ });
3051
+ }
3052
+ EntityHistoricData.GetList = GetList;
3053
+ /**
3054
+ * Returns historic data statistics for an array of Entity IDs.
3055
+ * @param params
3056
+ * @returns
3057
+ */
3058
+ function GetStats(params) {
3059
+ return __awaiter(this, void 0, void 0, function* () {
3060
+ let { entityIds, api, req } = params;
3061
+ // Save time and just return a none response if no entity IDs are provided.
3062
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3063
+ return {
3064
+ stats: []
3065
+ };
3066
+ }
3067
+ if (!api) {
3068
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
3069
+ }
3070
+ req = exports.Api.PrepReqParams(req);
3071
+ const cacheKey = GetStatsCacheKey(entityIds);
3072
+ const cached = api.GetCacheItem(cacheKey, req);
3073
+ if (cached === null || cached === void 0 ? void 0 : cached.found) {
3074
+ return cached.data;
3075
+ }
3076
+ const prom = yield api.POST("v1/entity/historicData/stats", {
3077
+ entityIds: entityIds
3078
+ }, req);
3079
+ api.SetCacheItem({
3080
+ key: cacheKey,
3081
+ value: prom,
3082
+ req: req,
3083
+ // Short cache. 60 seconds.
3084
+ duration: 60000
3085
+ });
3086
+ return prom;
3087
+ });
3088
+ }
3089
+ EntityHistoricData.GetStats = GetStats;
3090
+ /**
3091
+ * Creates or updates historic data records.
3092
+ * Please note that the expected input/output does not include internal fields found inside the "Bruce" attribute.
3093
+ * @param params
3094
+ * @returns
3095
+ */
3096
+ function Update(params) {
3097
+ var _a;
3098
+ return __awaiter(this, void 0, void 0, function* () {
3099
+ let { records, api, req } = params;
3100
+ // Save time and just return a none response if no records are provided.
3101
+ if (!(records === null || records === void 0 ? void 0 : records.length)) {
3102
+ return {
3103
+ records: []
3104
+ };
3105
+ }
3106
+ if (!api) {
3107
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
3108
+ }
3109
+ const res = yield api.POST("v1/entity/historicData", {
3110
+ records: records
3111
+ }, exports.Api.PrepReqParams(req));
3112
+ // Kill cache for every unique attrKey.
3113
+ let attrKeys = records.map(r => r.attrKey);
3114
+ attrKeys = attrKeys.filter((v, i) => attrKeys.indexOf(v) === i);
3115
+ for (const attrKey of attrKeys) {
3116
+ api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
3117
+ }
3118
+ // Kill any stats cache that includes any of the Entity IDs.
3119
+ if ((_a = res.records) === null || _a === void 0 ? void 0 : _a.length) {
3120
+ const entityIds = res.records.map(r => r.entityId).filter((v, i) => v && res.records.indexOf(v) === i);
3121
+ ClearCacheByEntityIds(api, entityIds);
3122
+ }
3123
+ return res;
3124
+ });
3125
+ }
3126
+ EntityHistoricData.Update = Update;
3127
+ /**
3128
+ * Deletes historic data records for an array of Entity IDs.
3129
+ * This deletes all records within a provided key + range.
3130
+ * @param params
3131
+ * @returns
3132
+ */
3133
+ function Delete(params) {
3134
+ return __awaiter(this, void 0, void 0, function* () {
3135
+ let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
3136
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3137
+ return;
3138
+ }
3139
+ if (!api) {
3140
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
3141
+ }
3142
+ if (!attrKey || !dateTimeFrom || !dateTimeTo) {
3143
+ throw new Error("Invalid parameters provided.");
3144
+ }
3145
+ if (typeof attrKey != "string") {
3146
+ attrKey = exports.PathUtils.Wrap(attrKey);
3147
+ }
3148
+ const urlParams = new URLSearchParams();
3149
+ for (const entityId of entityIds) {
3150
+ urlParams.append("entityId", entityId);
3151
+ }
3152
+ urlParams.append("attrKey", attrKey);
3153
+ urlParams.append("dateTimeFrom", dateTimeFrom);
3154
+ urlParams.append("dateTimeTo", dateTimeTo);
3155
+ yield api.DELETE(`v1/entity/historicData?${urlParams.toString()}`, exports.Api.PrepReqParams(req));
3156
+ // Kill cache for all Entity cached Entity records related to the attrKey.
3157
+ api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
3158
+ // Kill any stats cache that includes any of the Entity IDs.
3159
+ ClearCacheByEntityIds(api, entityIds);
3160
+ });
3161
+ }
3162
+ EntityHistoricData.Delete = Delete;
3163
+ function GetListCacheKey(entityIds, attrKey, dateTimeFrom, dateTimeTo) {
3164
+ return exports.Api.ECacheKey.EntityHistoricDataRec + exports.Api.ECacheKey.Id + entityIds.join(",") + exports.Api.ECacheKey.Id + attrKey + exports.Api.ECacheKey.Id + dateTimeFrom + exports.Api.ECacheKey.Id + dateTimeTo;
3165
+ }
3166
+ EntityHistoricData.GetListCacheKey = GetListCacheKey;
3167
+ function GetStatsCacheKey(entityIds) {
3168
+ return exports.Api.ECacheKey.EntityHistoricDataStats + exports.Api.ECacheKey.Id + entityIds.join(",");
3169
+ }
3170
+ EntityHistoricData.GetStatsCacheKey = GetStatsCacheKey;
3171
+ function ClearCacheByEntityIds(api, entityIds) {
3172
+ if (!api || !(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3173
+ return;
3174
+ }
3175
+ const REC_KEY_PREFIX = exports.Api.ECacheKey.EntityHistoricDataRec + exports.Api.ECacheKey.Id;
3176
+ const STATS_KEY_PREFIX = exports.Api.ECacheKey.EntityHistoricDataStats + exports.Api.ECacheKey.Id;
3177
+ api.Cache.RemoveByCallback((key) => {
3178
+ let keyStr = String(key);
3179
+ if (!keyStr.startsWith(STATS_KEY_PREFIX) && !keyStr.startsWith(REC_KEY_PREFIX)) {
3180
+ return false;
3181
+ }
3182
+ // Shorten to speed up the next step.
3183
+ keyStr = keyStr.replace(STATS_KEY_PREFIX, "").replace(REC_KEY_PREFIX, "");
3184
+ // Look for any matching Entity IDs.
3185
+ for (let i = 0; i < entityIds.length; i++) {
3186
+ const entityId = entityIds[i];
3187
+ if (keyStr.includes(entityId)) {
3188
+ return true;
3189
+ }
3190
+ }
3191
+ return false;
3192
+ });
3193
+ }
3194
+ EntityHistoricData.ClearCacheByEntityIds = ClearCacheByEntityIds;
3195
+ })(exports.EntityHistoricData || (exports.EntityHistoricData = {}));
3196
+
2997
3197
  (function (Entity) {
2998
3198
  /**
2999
3199
  * Returns an entity record for the given entity id.
@@ -3189,6 +3389,7 @@
3189
3389
  }
3190
3390
  yield api.DELETE(`entity/${entityId}`, exports.Api.PrepReqParams(reqParams));
3191
3391
  api.Cache.RemoveByContains(GetContainsKey(entityId));
3392
+ exports.EntityHistoricData.ClearCacheByEntityIds(api, [entityId]);
3192
3393
  });
3193
3394
  }
3194
3395
  Entity.Delete = Delete;
@@ -3212,6 +3413,7 @@
3212
3413
  const entityId = entityIds[i];
3213
3414
  api.Cache.RemoveByContains(GetContainsKey(entityId));
3214
3415
  }
3416
+ exports.EntityHistoricData.ClearCacheByEntityIds(api, entityIds);
3215
3417
  });
3216
3418
  }
3217
3419
  Entity.DeleteList = DeleteList;
@@ -3236,6 +3438,7 @@
3236
3438
  const reqUrl = `entity/${data.Bruce.ID}/?dataoverride=${override}&BruceEntityType=${data.Bruce["EntityType.ID"]}`;
3237
3439
  const res = yield api.POST(reqUrl, data, exports.Api.PrepReqParams(reqParams));
3238
3440
  api.Cache.RemoveByContains(GetContainsKey(data.Bruce.ID));
3441
+ exports.EntityHistoricData.ClearCacheByEntityIds(api, [data.Bruce.ID]);
3239
3442
  return {
3240
3443
  entity: res
3241
3444
  };
@@ -6677,130 +6880,6 @@
6677
6880
  EntityAttribute.AddAttribute = AddAttribute;
6678
6881
  })(exports.EntityAttribute || (exports.EntityAttribute = {}));
6679
6882
 
6680
- (function (EntityHistoricData) {
6681
- /**
6682
- * Returns historic data for an array of Entity IDs.
6683
- * A maximum number of records will be returned per Entity ID, this information is returned in the response.
6684
- * @param params
6685
- * @returns
6686
- */
6687
- function GetList(params) {
6688
- return __awaiter(this, void 0, void 0, function* () {
6689
- let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
6690
- // Save time and just return a none response if no entity IDs are provided.
6691
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6692
- return {
6693
- limitPerEntity: 0,
6694
- recordsByIds: {}
6695
- };
6696
- }
6697
- if (!api) {
6698
- api = exports.ENVIRONMENT.Api().GetBruceApi();
6699
- }
6700
- if (typeof attrKey != "string") {
6701
- attrKey = exports.PathUtils.Wrap(attrKey);
6702
- }
6703
- const urlParams = new URLSearchParams();
6704
- for (const entityId of entityIds) {
6705
- urlParams.append("entityId", entityId);
6706
- }
6707
- urlParams.append("attrKey", attrKey);
6708
- urlParams.append("dateTimeFrom", dateTimeFrom);
6709
- urlParams.append("dateTimeTo", dateTimeTo);
6710
- return yield api.GET(`v1/entity/historicData?${urlParams.toString()}`, exports.Api.PrepReqParams(req));
6711
- });
6712
- }
6713
- EntityHistoricData.GetList = GetList;
6714
- /**
6715
- * Returns historic data statistics for an array of Entity IDs.
6716
- * @param params
6717
- * @returns
6718
- */
6719
- function GetStats(params) {
6720
- return __awaiter(this, void 0, void 0, function* () {
6721
- let { entityIds, api, req } = params;
6722
- // Save time and just return a none response if no entity IDs are provided.
6723
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6724
- return {
6725
- stats: []
6726
- };
6727
- }
6728
- if (!api) {
6729
- api = exports.ENVIRONMENT.Api().GetBruceApi();
6730
- }
6731
- return yield api.POST("v1/entity/historicData/stats", {
6732
- entityIds: entityIds
6733
- }, exports.Api.PrepReqParams(req));
6734
- });
6735
- }
6736
- EntityHistoricData.GetStats = GetStats;
6737
- /**
6738
- * Creates or updates historic data records.
6739
- * Please note that the expected input/output does not include internal fields found inside the "Bruce" attribute.
6740
- * @param params
6741
- * @returns
6742
- */
6743
- function Update(params) {
6744
- return __awaiter(this, void 0, void 0, function* () {
6745
- let { records, api, req } = params;
6746
- // Save time and just return a none response if no records are provided.
6747
- if (!(records === null || records === void 0 ? void 0 : records.length)) {
6748
- return {
6749
- records: []
6750
- };
6751
- }
6752
- if (!api) {
6753
- api = exports.ENVIRONMENT.Api().GetBruceApi();
6754
- }
6755
- const res = yield api.POST("v1/entity/historicData", {
6756
- records: records
6757
- }, exports.Api.PrepReqParams(req));
6758
- // Kill cache for every unique attrKey.
6759
- let attrKeys = records.map(r => r.attrKey);
6760
- attrKeys = attrKeys.filter((v, i) => attrKeys.indexOf(v) === i);
6761
- for (const attrKey of attrKeys) {
6762
- api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
6763
- }
6764
- return res;
6765
- });
6766
- }
6767
- EntityHistoricData.Update = Update;
6768
- /**
6769
- * Deletes historic data records for an array of Entity IDs.
6770
- * This deletes all records within a provided key + range.
6771
- * @param params
6772
- * @returns
6773
- */
6774
- function Delete(params) {
6775
- return __awaiter(this, void 0, void 0, function* () {
6776
- let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
6777
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6778
- return;
6779
- }
6780
- if (!api) {
6781
- api = exports.ENVIRONMENT.Api().GetBruceApi();
6782
- }
6783
- if (!attrKey || !dateTimeFrom || !dateTimeTo) {
6784
- throw new Error("Invalid parameters provided.");
6785
- }
6786
- if (typeof attrKey != "string") {
6787
- attrKey = exports.PathUtils.Wrap(attrKey);
6788
- }
6789
- const urlParams = new URLSearchParams();
6790
- for (const entityId of entityIds) {
6791
- urlParams.append("entityId", entityId);
6792
- }
6793
- urlParams.append("attrKey", attrKey);
6794
- urlParams.append("dateTimeFrom", dateTimeFrom);
6795
- urlParams.append("dateTimeTo", dateTimeTo);
6796
- yield api.DELETE(`v1/entity/historicData?${urlParams.toString()}`, exports.Api.PrepReqParams(req));
6797
- // Kill cache for all Entity cached Entity records related to the attrKey.
6798
- api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
6799
- });
6800
- }
6801
- EntityHistoricData.Delete = Delete;
6802
- })(exports.EntityHistoricData || (exports.EntityHistoricData = {}));
6803
-
6804
6883
  (function (Uploader) {
6805
6884
  Uploader.MIN_LARGE_FILE_SIZE = 100000000; // 100MB.
6806
6885
  /**
@@ -11171,7 +11250,7 @@
11171
11250
  })(exports.DataSource || (exports.DataSource = {}));
11172
11251
 
11173
11252
  // This is updated with the package.json version on build.
11174
- const VERSION = "3.9.2";
11253
+ const VERSION = "3.9.3";
11175
11254
 
11176
11255
  exports.VERSION = VERSION;
11177
11256
  exports.AbstractApi = AbstractApi;