bruce-models 7.1.74 → 7.1.76
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 +407 -5
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +407 -5
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/api/api.js +3 -0
- package/dist/lib/api/api.js.map +1 -1
- package/dist/lib/bruce-models.js +1 -1
- package/dist/lib/entity/entity-historic-data.js +402 -4
- package/dist/lib/entity/entity-historic-data.js.map +1 -1
- package/dist/lib/entity/entity.js +1 -0
- package/dist/lib/entity/entity.js.map +1 -1
- package/dist/lib/project/menu-item.js.map +1 -1
- package/dist/types/api/api.d.ts +3 -0
- package/dist/types/bruce-models.d.ts +1 -1
- package/dist/types/entity/entity-historic-data.d.ts +222 -0
- package/dist/types/entity/entity.d.ts +10 -1
- package/dist/types/project/menu-item.d.ts +1 -0
- package/package.json +1 -1
package/dist/bruce-models.umd.js
CHANGED
|
@@ -90,6 +90,9 @@
|
|
|
90
90
|
ECacheKey["EntityHistoricData"] = "entityhistoricdata";
|
|
91
91
|
ECacheKey["EntityHistoricDataRec"] = "entityhistoricdatarec";
|
|
92
92
|
ECacheKey["EntityHistoricDataStats"] = "entityhistoricdatastats";
|
|
93
|
+
ECacheKey["EntityHistoricDataSeries"] = "entityhistoricdataseries";
|
|
94
|
+
ECacheKey["EntityHistoricDataAnalysis"] = "entityhistoricdataanalysis";
|
|
95
|
+
ECacheKey["EntityHistoricDataPage"] = "entityhistoricdatapage";
|
|
93
96
|
ECacheKey["AccountLimits"] = "accountlimits";
|
|
94
97
|
})(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
|
|
95
98
|
// 1 minute.
|
|
@@ -4776,9 +4779,16 @@
|
|
|
4776
4779
|
})(exports.PathUtils || (exports.PathUtils = {}));
|
|
4777
4780
|
|
|
4778
4781
|
(function (EntityHistoricData) {
|
|
4782
|
+
// How long a v3 historic read stays good when the caller says the data is not changing under it.
|
|
4783
|
+
// Historic records for a past range are immutable until something writes, and a write invalidates
|
|
4784
|
+
// through ClearCacheByEntityIds, so holding them is safe rather than merely convenient.
|
|
4785
|
+
EntityHistoricData.STATIC_CACHE_DURATION = 15 * 60 * 1000;
|
|
4786
|
+
// The live case genuinely gains records as it runs, so it keeps a short window.
|
|
4787
|
+
EntityHistoricData.LIVE_CACHE_DURATION = 30 * 1000;
|
|
4779
4788
|
/**
|
|
4780
4789
|
* Returns historic data for an array of Entity IDs.
|
|
4781
4790
|
* A maximum number of records will be returned per Entity ID, this information is returned in the response.
|
|
4791
|
+
* @deprecated Don't use.
|
|
4782
4792
|
* @param params
|
|
4783
4793
|
* @returns
|
|
4784
4794
|
*/
|
|
@@ -4874,6 +4884,7 @@
|
|
|
4874
4884
|
EntityHistoricData.GetList = GetList;
|
|
4875
4885
|
/**
|
|
4876
4886
|
* Returns historic data statistics for an array of Entity IDs.
|
|
4887
|
+
* @deprecated Don't use.
|
|
4877
4888
|
* @param params
|
|
4878
4889
|
* @returns
|
|
4879
4890
|
*/
|
|
@@ -4913,6 +4924,7 @@
|
|
|
4913
4924
|
/**
|
|
4914
4925
|
* Creates or updates historic data records.
|
|
4915
4926
|
* Please note that the expected input/output does not include internal fields found inside the "Bruce" attribute.
|
|
4927
|
+
* @deprecated Don't use.
|
|
4916
4928
|
* @param params
|
|
4917
4929
|
* @returns
|
|
4918
4930
|
*/
|
|
@@ -4950,6 +4962,7 @@
|
|
|
4950
4962
|
/**
|
|
4951
4963
|
* Deletes historic data records for an array of Entity IDs.
|
|
4952
4964
|
* This deletes all records within a provided key + range.
|
|
4965
|
+
* @deprecated Don't use.
|
|
4953
4966
|
* @param params
|
|
4954
4967
|
* @returns
|
|
4955
4968
|
*/
|
|
@@ -4983,6 +4996,388 @@
|
|
|
4983
4996
|
});
|
|
4984
4997
|
}
|
|
4985
4998
|
EntityHistoricData.Delete = Delete;
|
|
4999
|
+
/*
|
|
5000
|
+
* Returns how long a read may be held, based on whether the caller is tracking live data.
|
|
5001
|
+
*/
|
|
5002
|
+
function CacheDurationFor(live) {
|
|
5003
|
+
return live === false ? EntityHistoricData.STATIC_CACHE_DURATION : EntityHistoricData.LIVE_CACHE_DURATION;
|
|
5004
|
+
}
|
|
5005
|
+
/*
|
|
5006
|
+
* Shared body for the v3 historic reads, which all post to the same route.
|
|
5007
|
+
*/
|
|
5008
|
+
function BuildV3Filter(params) {
|
|
5009
|
+
const { entityIds, entityTypeId, attrKey, dateTimeFrom, dateTimeTo, scenario } = params;
|
|
5010
|
+
const body = {};
|
|
5011
|
+
if (entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) {
|
|
5012
|
+
body["Entity.ID"] = entityIds;
|
|
5013
|
+
}
|
|
5014
|
+
if (entityTypeId) {
|
|
5015
|
+
body["EntityType.ID"] = entityTypeId;
|
|
5016
|
+
}
|
|
5017
|
+
if (attrKey) {
|
|
5018
|
+
body["AttrKey"] = typeof attrKey == "string" ? attrKey : exports.PathUtils.Wrap(attrKey);
|
|
5019
|
+
}
|
|
5020
|
+
if (dateTimeFrom) {
|
|
5021
|
+
body["DateTimeFrom"] = dateTimeFrom;
|
|
5022
|
+
}
|
|
5023
|
+
if (dateTimeTo) {
|
|
5024
|
+
body["DateTimeTo"] = dateTimeTo;
|
|
5025
|
+
}
|
|
5026
|
+
if (scenario) {
|
|
5027
|
+
body["Scenario"] = scenario;
|
|
5028
|
+
}
|
|
5029
|
+
return body;
|
|
5030
|
+
}
|
|
5031
|
+
/**
|
|
5032
|
+
* Returns a histogram of where historic records sit in time, without returning the records.
|
|
5033
|
+
* Answers "when does this data exist" for a timeline in one request, at a cost that does not grow with the number of records.
|
|
5034
|
+
* @param params
|
|
5035
|
+
* @returns
|
|
5036
|
+
*/
|
|
5037
|
+
function GetAnalysis(params) {
|
|
5038
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5039
|
+
let { entityIds, entityTypeId, buckets, api, req } = params;
|
|
5040
|
+
if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) && !entityTypeId) {
|
|
5041
|
+
return { analysis: [] };
|
|
5042
|
+
}
|
|
5043
|
+
if (!api) {
|
|
5044
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
5045
|
+
}
|
|
5046
|
+
req = exports.Api.PrepReqParams(req);
|
|
5047
|
+
const body = BuildV3Filter(params);
|
|
5048
|
+
body["Analysis"] = true;
|
|
5049
|
+
if (buckets > 0) {
|
|
5050
|
+
body["Buckets"] = buckets;
|
|
5051
|
+
}
|
|
5052
|
+
const cacheKey = exports.Api.ECacheKey.EntityHistoricDataAnalysis + exports.Api.ECacheKey.Id + JSON.stringify(body);
|
|
5053
|
+
const cached = api.GetCacheItem(cacheKey, req);
|
|
5054
|
+
if (cached === null || cached === void 0 ? void 0 : cached.found) {
|
|
5055
|
+
return cached.data;
|
|
5056
|
+
}
|
|
5057
|
+
const prom = api.POST("v3/entities/getHistoric", body, req).then((res) => {
|
|
5058
|
+
return { analysis: ((res === null || res === void 0 ? void 0 : res.Items) || []) };
|
|
5059
|
+
});
|
|
5060
|
+
api.SetCacheItem({
|
|
5061
|
+
key: cacheKey,
|
|
5062
|
+
value: prom,
|
|
5063
|
+
req: req,
|
|
5064
|
+
duration: CacheDurationFor(params.live)
|
|
5065
|
+
});
|
|
5066
|
+
return prom;
|
|
5067
|
+
});
|
|
5068
|
+
}
|
|
5069
|
+
EntityHistoricData.GetAnalysis = GetAnalysis;
|
|
5070
|
+
/**
|
|
5071
|
+
* Returns the date range and record count per attribute key, in the shape GetStats returns.
|
|
5072
|
+
* Prefer GetAnalysis directly, which also carries the distribution.
|
|
5073
|
+
* @param params
|
|
5074
|
+
* @returns
|
|
5075
|
+
*/
|
|
5076
|
+
function GetRanges(params) {
|
|
5077
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5078
|
+
// One bucket, since the distribution costs work to build and no caller of this reads it.
|
|
5079
|
+
const { analysis } = yield GetAnalysis(Object.assign(Object.assign({}, params), { buckets: 1 }));
|
|
5080
|
+
return {
|
|
5081
|
+
stats: (analysis || []).map(a => ({
|
|
5082
|
+
attrKey: a.AttrKey,
|
|
5083
|
+
dateTimeMin: a.DateTimeMin,
|
|
5084
|
+
dateTimeMax: a.DateTimeMax,
|
|
5085
|
+
count: a.Count
|
|
5086
|
+
}))
|
|
5087
|
+
};
|
|
5088
|
+
});
|
|
5089
|
+
}
|
|
5090
|
+
EntityHistoricData.GetRanges = GetRanges;
|
|
5091
|
+
/**
|
|
5092
|
+
* Returns a numeric attribute aggregated into time buckets, computed in the database.
|
|
5093
|
+
* This is what a chart wants: the reduction happens server-side, so the response is the size of
|
|
5094
|
+
* the plotted series rather than the size of the underlying records.
|
|
5095
|
+
* @param params
|
|
5096
|
+
* @returns
|
|
5097
|
+
*/
|
|
5098
|
+
function GetSeries(params) {
|
|
5099
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5100
|
+
let { entityIds, entityTypeId, valueAttrKey, aggregate, interval, api, req } = params;
|
|
5101
|
+
const empty = {
|
|
5102
|
+
AttrKey: null,
|
|
5103
|
+
Aggregate: aggregate || "avg",
|
|
5104
|
+
Interval: interval || "day",
|
|
5105
|
+
DateTimeMin: null,
|
|
5106
|
+
DateTimeMax: null,
|
|
5107
|
+
PointCount: 0,
|
|
5108
|
+
Points: []
|
|
5109
|
+
};
|
|
5110
|
+
if ((!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) && !entityTypeId) || !valueAttrKey) {
|
|
5111
|
+
return { series: empty };
|
|
5112
|
+
}
|
|
5113
|
+
if (!api) {
|
|
5114
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
5115
|
+
}
|
|
5116
|
+
req = exports.Api.PrepReqParams(req);
|
|
5117
|
+
const body = BuildV3Filter(params);
|
|
5118
|
+
body["Select"] = { Type: "CALC" };
|
|
5119
|
+
body["selectAttrKey"] = typeof valueAttrKey == "string" ? valueAttrKey : exports.PathUtils.Wrap(valueAttrKey);
|
|
5120
|
+
if (aggregate) {
|
|
5121
|
+
body["aggregate"] = aggregate;
|
|
5122
|
+
}
|
|
5123
|
+
if (interval) {
|
|
5124
|
+
body["interval"] = interval;
|
|
5125
|
+
}
|
|
5126
|
+
const cacheKey = exports.Api.ECacheKey.EntityHistoricDataSeries + exports.Api.ECacheKey.Id + JSON.stringify(body);
|
|
5127
|
+
const cached = api.GetCacheItem(cacheKey, req);
|
|
5128
|
+
if (cached === null || cached === void 0 ? void 0 : cached.found) {
|
|
5129
|
+
return cached.data;
|
|
5130
|
+
}
|
|
5131
|
+
const prom = api.POST("v3/entities/getHistoric", body, req).then((res) => {
|
|
5132
|
+
var _a;
|
|
5133
|
+
return { series: (((_a = res === null || res === void 0 ? void 0 : res.Items) === null || _a === void 0 ? void 0 : _a[0]) || empty) };
|
|
5134
|
+
});
|
|
5135
|
+
api.SetCacheItem({
|
|
5136
|
+
key: cacheKey,
|
|
5137
|
+
value: prom,
|
|
5138
|
+
req: req,
|
|
5139
|
+
duration: CacheDurationFor(params.live)
|
|
5140
|
+
});
|
|
5141
|
+
return prom;
|
|
5142
|
+
});
|
|
5143
|
+
}
|
|
5144
|
+
EntityHistoricData.GetSeries = GetSeries;
|
|
5145
|
+
/**
|
|
5146
|
+
* Returns one aggregated series per Entity, computed in the database in a single request.
|
|
5147
|
+
* @param params
|
|
5148
|
+
* @returns
|
|
5149
|
+
*/
|
|
5150
|
+
function GetSeriesByEntity(params) {
|
|
5151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5152
|
+
let { entityIds, entityTypeId, valueAttrKey, aggregate, interval, api, req } = params;
|
|
5153
|
+
if ((!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) && !entityTypeId) || !valueAttrKey) {
|
|
5154
|
+
return { seriesByIds: {} };
|
|
5155
|
+
}
|
|
5156
|
+
if (!api) {
|
|
5157
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
5158
|
+
}
|
|
5159
|
+
req = exports.Api.PrepReqParams(req);
|
|
5160
|
+
const body = BuildV3Filter(params);
|
|
5161
|
+
body["Select"] = { Type: "CALC" };
|
|
5162
|
+
body["selectAttrKey"] = typeof valueAttrKey == "string" ? valueAttrKey : exports.PathUtils.Wrap(valueAttrKey);
|
|
5163
|
+
body["GroupBy"] = "Entity";
|
|
5164
|
+
if (aggregate) {
|
|
5165
|
+
body["aggregate"] = aggregate;
|
|
5166
|
+
}
|
|
5167
|
+
if (interval) {
|
|
5168
|
+
body["interval"] = interval;
|
|
5169
|
+
}
|
|
5170
|
+
const cacheKey = exports.Api.ECacheKey.EntityHistoricDataSeries + exports.Api.ECacheKey.Id + JSON.stringify(body);
|
|
5171
|
+
const cached = api.GetCacheItem(cacheKey, req);
|
|
5172
|
+
if (cached === null || cached === void 0 ? void 0 : cached.found) {
|
|
5173
|
+
return cached.data;
|
|
5174
|
+
}
|
|
5175
|
+
const prom = api.POST("v3/entities/getHistoric", body, req).then((res) => {
|
|
5176
|
+
const seriesByIds = {};
|
|
5177
|
+
for (const series of ((res === null || res === void 0 ? void 0 : res.Items) || [])) {
|
|
5178
|
+
const entityId = series === null || series === void 0 ? void 0 : series["Entity.ID"];
|
|
5179
|
+
if (entityId) {
|
|
5180
|
+
seriesByIds[entityId] = series;
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
return { seriesByIds };
|
|
5184
|
+
});
|
|
5185
|
+
api.SetCacheItem({
|
|
5186
|
+
key: cacheKey,
|
|
5187
|
+
value: prom,
|
|
5188
|
+
req: req,
|
|
5189
|
+
duration: CacheDurationFor(params.live)
|
|
5190
|
+
});
|
|
5191
|
+
return prom;
|
|
5192
|
+
});
|
|
5193
|
+
}
|
|
5194
|
+
EntityHistoricData.GetSeriesByEntity = GetSeriesByEntity;
|
|
5195
|
+
/**
|
|
5196
|
+
* Returns one page of historic records, newest first by default.
|
|
5197
|
+
* @param params
|
|
5198
|
+
* @returns
|
|
5199
|
+
*/
|
|
5200
|
+
function GetPage(params) {
|
|
5201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5202
|
+
let { entityIds, entityTypeId, pageIndex, pageSize, orderBy, orderDir, api, req } = params;
|
|
5203
|
+
if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) && !entityTypeId) {
|
|
5204
|
+
return { items: [], pageIndex: 0, pageSize: 0, sample: 0 };
|
|
5205
|
+
}
|
|
5206
|
+
if (!api) {
|
|
5207
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
5208
|
+
}
|
|
5209
|
+
req = exports.Api.PrepReqParams(req);
|
|
5210
|
+
const body = BuildV3Filter(params);
|
|
5211
|
+
if (params.sample > 0) {
|
|
5212
|
+
body["Sample"] = params.sample;
|
|
5213
|
+
}
|
|
5214
|
+
else {
|
|
5215
|
+
body["PageIndex"] = pageIndex > 0 ? pageIndex : 0;
|
|
5216
|
+
if (pageSize > 0) {
|
|
5217
|
+
body["PageSize"] = pageSize;
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
if (orderBy) {
|
|
5221
|
+
body["OrderBy"] = orderBy;
|
|
5222
|
+
}
|
|
5223
|
+
if (orderDir) {
|
|
5224
|
+
body["OrderDir"] = orderDir;
|
|
5225
|
+
}
|
|
5226
|
+
const cacheKey = exports.Api.ECacheKey.EntityHistoricDataPage + exports.Api.ECacheKey.Id + JSON.stringify(body);
|
|
5227
|
+
const cached = api.GetCacheItem(cacheKey, req);
|
|
5228
|
+
if (cached === null || cached === void 0 ? void 0 : cached.found) {
|
|
5229
|
+
return cached.data;
|
|
5230
|
+
}
|
|
5231
|
+
const prom = api.POST("v3/entities/getHistoric", body, req).then((res) => {
|
|
5232
|
+
var _a, _b, _c;
|
|
5233
|
+
return {
|
|
5234
|
+
items: (res === null || res === void 0 ? void 0 : res.Items) || [],
|
|
5235
|
+
pageIndex: (_a = res === null || res === void 0 ? void 0 : res.PageIndex) !== null && _a !== void 0 ? _a : 0,
|
|
5236
|
+
pageSize: (_b = res === null || res === void 0 ? void 0 : res.PageSize) !== null && _b !== void 0 ? _b : 0,
|
|
5237
|
+
sample: (_c = res === null || res === void 0 ? void 0 : res.Sample) !== null && _c !== void 0 ? _c : 0
|
|
5238
|
+
};
|
|
5239
|
+
});
|
|
5240
|
+
api.SetCacheItem({
|
|
5241
|
+
key: cacheKey,
|
|
5242
|
+
value: prom,
|
|
5243
|
+
req: req,
|
|
5244
|
+
duration: CacheDurationFor(params.live)
|
|
5245
|
+
});
|
|
5246
|
+
return prom;
|
|
5247
|
+
});
|
|
5248
|
+
}
|
|
5249
|
+
EntityHistoricData.GetPage = GetPage;
|
|
5250
|
+
/*
|
|
5251
|
+
* Converts a v3 record into the flatter shape the render engines consume.
|
|
5252
|
+
*/
|
|
5253
|
+
function ToDataRecord(record) {
|
|
5254
|
+
const entity = (record === null || record === void 0 ? void 0 : record.Entity) || {};
|
|
5255
|
+
const bruce = entity.Bruce || {};
|
|
5256
|
+
const data = Object.assign({}, entity);
|
|
5257
|
+
delete data.Bruce;
|
|
5258
|
+
return {
|
|
5259
|
+
attrKey: record === null || record === void 0 ? void 0 : record.AttrKey,
|
|
5260
|
+
dateTime: record === null || record === void 0 ? void 0 : record.DateTime,
|
|
5261
|
+
entityId: record === null || record === void 0 ? void 0 : record["Entity.ID"],
|
|
5262
|
+
data: data,
|
|
5263
|
+
location: bruce.Location,
|
|
5264
|
+
transform: bruce.Transform,
|
|
5265
|
+
boundaries: bruce.Boundaries,
|
|
5266
|
+
geometry: bruce.VectorGeometry
|
|
5267
|
+
};
|
|
5268
|
+
}
|
|
5269
|
+
EntityHistoricData.ToDataRecord = ToDataRecord;
|
|
5270
|
+
/**
|
|
5271
|
+
* Returns records grouped per Entity.
|
|
5272
|
+
* @param params
|
|
5273
|
+
* @returns
|
|
5274
|
+
*/
|
|
5275
|
+
function GetRecordsByEntity(params) {
|
|
5276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5277
|
+
const { entityIds, entityTypeId } = params;
|
|
5278
|
+
if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length) && !entityTypeId) {
|
|
5279
|
+
return { recordsByIds: {}, sample: 0 };
|
|
5280
|
+
}
|
|
5281
|
+
const page = yield GetPage(Object.assign(Object.assign({}, params), { pageSize: params.sample > 0 ? undefined : (params.pageSize || 1000) }));
|
|
5282
|
+
const recordsByIds = {};
|
|
5283
|
+
for (const item of page.items) {
|
|
5284
|
+
const record = ToDataRecord(item);
|
|
5285
|
+
if (!record.entityId) {
|
|
5286
|
+
continue;
|
|
5287
|
+
}
|
|
5288
|
+
if (!recordsByIds[record.entityId]) {
|
|
5289
|
+
recordsByIds[record.entityId] = [];
|
|
5290
|
+
}
|
|
5291
|
+
recordsByIds[record.entityId].push(record);
|
|
5292
|
+
}
|
|
5293
|
+
for (const entityId of Object.keys(recordsByIds)) {
|
|
5294
|
+
recordsByIds[entityId].sort((a, b) => new Date(a.dateTime).getTime() - new Date(b.dateTime).getTime());
|
|
5295
|
+
}
|
|
5296
|
+
return { recordsByIds, sample: page.sample };
|
|
5297
|
+
});
|
|
5298
|
+
}
|
|
5299
|
+
EntityHistoricData.GetRecordsByEntity = GetRecordsByEntity;
|
|
5300
|
+
/*
|
|
5301
|
+
* Assembles a v3 record, nesting the platform managed values where a read reports them.
|
|
5302
|
+
*/
|
|
5303
|
+
function BuildRecord(params) {
|
|
5304
|
+
const { entityId, attrKey, dateTime, values, internal, scenario } = params;
|
|
5305
|
+
const entity = Object.assign({}, (values || {}));
|
|
5306
|
+
if (internal) {
|
|
5307
|
+
entity.Bruce = Object.assign(Object.assign({}, (entity.Bruce || {})), internal);
|
|
5308
|
+
}
|
|
5309
|
+
const record = {
|
|
5310
|
+
"Entity.ID": entityId,
|
|
5311
|
+
AttrKey: typeof attrKey == "string" ? attrKey : exports.PathUtils.Wrap(attrKey),
|
|
5312
|
+
DateTime: dateTime,
|
|
5313
|
+
Entity: entity
|
|
5314
|
+
};
|
|
5315
|
+
if (scenario) {
|
|
5316
|
+
record.Scenario = scenario;
|
|
5317
|
+
}
|
|
5318
|
+
return record;
|
|
5319
|
+
}
|
|
5320
|
+
EntityHistoricData.BuildRecord = BuildRecord;
|
|
5321
|
+
/**
|
|
5322
|
+
* Creates or updates historic records.
|
|
5323
|
+
* @param params
|
|
5324
|
+
* @returns
|
|
5325
|
+
*/
|
|
5326
|
+
function Save(params) {
|
|
5327
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5328
|
+
let { records, scenario, api, req } = params;
|
|
5329
|
+
if (!(records === null || records === void 0 ? void 0 : records.length)) {
|
|
5330
|
+
return { records: [], warnings: [] };
|
|
5331
|
+
}
|
|
5332
|
+
if (!api) {
|
|
5333
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
5334
|
+
}
|
|
5335
|
+
const body = { Items: records };
|
|
5336
|
+
if (scenario) {
|
|
5337
|
+
body["Scenario"] = scenario;
|
|
5338
|
+
}
|
|
5339
|
+
const res = yield api.POST("v3/entities/historic", body, exports.Api.PrepReqParams(req));
|
|
5340
|
+
const entityIds = records.map(r => r["Entity.ID"]).filter((v, i, a) => v && a.indexOf(v) === i);
|
|
5341
|
+
ClearCacheByEntityIds(api, entityIds);
|
|
5342
|
+
for (const attrKey of records.map(r => r.AttrKey).filter((v, i, a) => v && a.indexOf(v) === i)) {
|
|
5343
|
+
api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
|
|
5344
|
+
}
|
|
5345
|
+
return {
|
|
5346
|
+
records: ((res === null || res === void 0 ? void 0 : res.Items) || []),
|
|
5347
|
+
warnings: ((res === null || res === void 0 ? void 0 : res.Warning) || [])
|
|
5348
|
+
};
|
|
5349
|
+
});
|
|
5350
|
+
}
|
|
5351
|
+
EntityHistoricData.Save = Save;
|
|
5352
|
+
/**
|
|
5353
|
+
* Deletes every historic record matching the filter, and reports how many were removed.
|
|
5354
|
+
* The filter is the one the reads accept, so a caller can delete exactly what it just listed.
|
|
5355
|
+
* @param params
|
|
5356
|
+
* @returns
|
|
5357
|
+
*/
|
|
5358
|
+
function DeleteRange(params) {
|
|
5359
|
+
var _a;
|
|
5360
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5361
|
+
let { entityIds, attrKey, dateTimeFrom, dateTimeTo, scenario, api, req } = params;
|
|
5362
|
+
if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
|
|
5363
|
+
return { deleted: 0 };
|
|
5364
|
+
}
|
|
5365
|
+
if (!api) {
|
|
5366
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
5367
|
+
}
|
|
5368
|
+
if (!scenario && (!attrKey || !dateTimeFrom || !dateTimeTo)) {
|
|
5369
|
+
throw new Error("Deleting outside a Scenario requires attrKey, dateTimeFrom and dateTimeTo.");
|
|
5370
|
+
}
|
|
5371
|
+
const body = BuildV3Filter(params);
|
|
5372
|
+
const res = yield api.POST("v3/entities/deleteHistoric", body, exports.Api.PrepReqParams(req));
|
|
5373
|
+
if (attrKey) {
|
|
5374
|
+
api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(typeof attrKey == "string" ? attrKey : exports.PathUtils.Wrap(attrKey)));
|
|
5375
|
+
}
|
|
5376
|
+
ClearCacheByEntityIds(api, entityIds);
|
|
5377
|
+
return { deleted: (_a = res === null || res === void 0 ? void 0 : res.Deleted) !== null && _a !== void 0 ? _a : 0 };
|
|
5378
|
+
});
|
|
5379
|
+
}
|
|
5380
|
+
EntityHistoricData.DeleteRange = DeleteRange;
|
|
4986
5381
|
function GetListCacheKey(entityIds, attrKey, dateTimeFrom, dateTimeTo) {
|
|
4987
5382
|
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;
|
|
4988
5383
|
}
|
|
@@ -5001,15 +5396,21 @@
|
|
|
5001
5396
|
if (!api || !(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
|
|
5002
5397
|
return;
|
|
5003
5398
|
}
|
|
5004
|
-
const
|
|
5005
|
-
|
|
5399
|
+
const PREFIXES = [
|
|
5400
|
+
exports.Api.ECacheKey.EntityHistoricDataRec + exports.Api.ECacheKey.Id,
|
|
5401
|
+
exports.Api.ECacheKey.EntityHistoricDataStats + exports.Api.ECacheKey.Id,
|
|
5402
|
+
exports.Api.ECacheKey.EntityHistoricDataSeries + exports.Api.ECacheKey.Id,
|
|
5403
|
+
exports.Api.ECacheKey.EntityHistoricDataAnalysis + exports.Api.ECacheKey.Id,
|
|
5404
|
+
exports.Api.ECacheKey.EntityHistoricDataPage + exports.Api.ECacheKey.Id
|
|
5405
|
+
];
|
|
5006
5406
|
api.Cache.RemoveByCallback((key) => {
|
|
5007
5407
|
let keyStr = String(key);
|
|
5008
|
-
|
|
5408
|
+
const prefix = PREFIXES.find(p => keyStr.startsWith(p));
|
|
5409
|
+
if (!prefix) {
|
|
5009
5410
|
return false;
|
|
5010
5411
|
}
|
|
5011
5412
|
// Shorten to speed up the next step.
|
|
5012
|
-
keyStr = keyStr.replace(
|
|
5413
|
+
keyStr = keyStr.replace(prefix, "");
|
|
5013
5414
|
// Look for any matching Entity IDs.
|
|
5014
5415
|
for (let i = 0; i < entityIds.length; i++) {
|
|
5015
5416
|
const entityId = entityIds[i];
|
|
@@ -5996,6 +6397,7 @@
|
|
|
5996
6397
|
(function (EOutlineKind) {
|
|
5997
6398
|
EOutlineKind["Entity"] = "ENTITY";
|
|
5998
6399
|
EOutlineKind["Attribute"] = "ATTRIBUTE";
|
|
6400
|
+
EOutlineKind["Reference"] = "REFERENCE";
|
|
5999
6401
|
})(EOutlineKind = Entity.EOutlineKind || (Entity.EOutlineKind = {}));
|
|
6000
6402
|
/**
|
|
6001
6403
|
* Returns an entity record for the given entity id.
|
|
@@ -19608,7 +20010,7 @@
|
|
|
19608
20010
|
})(exports.UrlUtils || (exports.UrlUtils = {}));
|
|
19609
20011
|
|
|
19610
20012
|
// This is updated with the package.json version on build.
|
|
19611
|
-
const VERSION = "7.1.
|
|
20013
|
+
const VERSION = "7.1.76";
|
|
19612
20014
|
|
|
19613
20015
|
exports.VERSION = VERSION;
|
|
19614
20016
|
exports.AbstractApi = AbstractApi;
|