bruce-models 3.9.2 → 3.9.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.
@@ -73,6 +73,8 @@ var Api;
73
73
  ECacheKey["Plugin"] = "plugin";
74
74
  ECacheKey["PluginIndexFile"] = "pluginindexfile";
75
75
  ECacheKey["EntityHistoricData"] = "entityhistoricdata";
76
+ ECacheKey["EntityHistoricDataRec"] = "entityhistoricdatarec";
77
+ ECacheKey["EntityHistoricDataStats"] = "entityhistoricdatastats";
76
78
  })(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
77
79
  // 1 minute.
78
80
  Api.DEFAULT_CACHE_DURATION = 60 * 1000;
@@ -239,6 +241,13 @@ class CacheControl {
239
241
  RemoveByContains(text) {
240
242
  this.RemoveBy(key => String(key).includes(String(text)));
241
243
  }
244
+ /**
245
+ * Removes items based on a callback's response.
246
+ * @param callback
247
+ */
248
+ RemoveByCallback(callback) {
249
+ this.RemoveBy(callback);
250
+ }
242
251
  }
243
252
 
244
253
  // TODO: Currently checks for CSV vs json specifically,
@@ -3041,6 +3050,198 @@ var ZoomControl;
3041
3050
  })(EDisplayType = ZoomControl.EDisplayType || (ZoomControl.EDisplayType = {}));
3042
3051
  })(ZoomControl || (ZoomControl = {}));
3043
3052
 
3053
+ var EntityHistoricData;
3054
+ (function (EntityHistoricData) {
3055
+ /**
3056
+ * Returns historic data for an array of Entity IDs.
3057
+ * A maximum number of records will be returned per Entity ID, this information is returned in the response.
3058
+ * @param params
3059
+ * @returns
3060
+ */
3061
+ function GetList(params) {
3062
+ return __awaiter(this, void 0, void 0, function* () {
3063
+ let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
3064
+ // Save time and just return a none response if no entity IDs are provided.
3065
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3066
+ return {
3067
+ limitPerEntity: 0,
3068
+ recordsByIds: {}
3069
+ };
3070
+ }
3071
+ if (!api) {
3072
+ api = ENVIRONMENT.Api().GetBruceApi();
3073
+ }
3074
+ if (typeof attrKey != "string") {
3075
+ attrKey = PathUtils.Wrap(attrKey);
3076
+ }
3077
+ const cacheKey = GetListCacheKey(entityIds, attrKey, dateTimeFrom, dateTimeTo);
3078
+ const cached = api.GetCacheItem(cacheKey, req);
3079
+ if (cached === null || cached === void 0 ? void 0 : cached.found) {
3080
+ return cached.data;
3081
+ }
3082
+ const urlParams = new URLSearchParams();
3083
+ for (const entityId of entityIds) {
3084
+ urlParams.append("entityId", entityId);
3085
+ }
3086
+ urlParams.append("attrKey", attrKey);
3087
+ urlParams.append("dateTimeFrom", dateTimeFrom);
3088
+ urlParams.append("dateTimeTo", dateTimeTo);
3089
+ const prom = api.GET(`v1/entity/historicData?${urlParams.toString()}`, Api.PrepReqParams(req));
3090
+ api.SetCacheItem({
3091
+ key: cacheKey,
3092
+ value: prom,
3093
+ req: req,
3094
+ // Short cache. 30 seconds.
3095
+ duration: 30000
3096
+ });
3097
+ return prom;
3098
+ });
3099
+ }
3100
+ EntityHistoricData.GetList = GetList;
3101
+ /**
3102
+ * Returns historic data statistics for an array of Entity IDs.
3103
+ * @param params
3104
+ * @returns
3105
+ */
3106
+ function GetStats(params) {
3107
+ return __awaiter(this, void 0, void 0, function* () {
3108
+ let { entityIds, api, req } = params;
3109
+ // Save time and just return a none response if no entity IDs are provided.
3110
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3111
+ return {
3112
+ stats: []
3113
+ };
3114
+ }
3115
+ if (!api) {
3116
+ api = ENVIRONMENT.Api().GetBruceApi();
3117
+ }
3118
+ req = Api.PrepReqParams(req);
3119
+ const cacheKey = GetStatsCacheKey(entityIds);
3120
+ const cached = api.GetCacheItem(cacheKey, req);
3121
+ if (cached === null || cached === void 0 ? void 0 : cached.found) {
3122
+ return cached.data;
3123
+ }
3124
+ const prom = yield api.POST("v1/entity/historicData/stats", {
3125
+ entityIds: entityIds
3126
+ }, req);
3127
+ api.SetCacheItem({
3128
+ key: cacheKey,
3129
+ value: prom,
3130
+ req: req,
3131
+ // Short cache. 60 seconds.
3132
+ duration: 60000
3133
+ });
3134
+ return prom;
3135
+ });
3136
+ }
3137
+ EntityHistoricData.GetStats = GetStats;
3138
+ /**
3139
+ * Creates or updates historic data records.
3140
+ * Please note that the expected input/output does not include internal fields found inside the "Bruce" attribute.
3141
+ * @param params
3142
+ * @returns
3143
+ */
3144
+ function Update(params) {
3145
+ var _a;
3146
+ return __awaiter(this, void 0, void 0, function* () {
3147
+ let { records, api, req } = params;
3148
+ // Save time and just return a none response if no records are provided.
3149
+ if (!(records === null || records === void 0 ? void 0 : records.length)) {
3150
+ return {
3151
+ records: []
3152
+ };
3153
+ }
3154
+ if (!api) {
3155
+ api = ENVIRONMENT.Api().GetBruceApi();
3156
+ }
3157
+ const res = yield api.POST("v1/entity/historicData", {
3158
+ records: records
3159
+ }, Api.PrepReqParams(req));
3160
+ // Kill cache for every unique attrKey.
3161
+ let attrKeys = records.map(r => r.attrKey);
3162
+ attrKeys = attrKeys.filter((v, i) => attrKeys.indexOf(v) === i);
3163
+ for (const attrKey of attrKeys) {
3164
+ api.Cache.RemoveByContains(Entity.GetHistoricContainsKey(attrKey));
3165
+ }
3166
+ // Kill any stats cache that includes any of the Entity IDs.
3167
+ if ((_a = res.records) === null || _a === void 0 ? void 0 : _a.length) {
3168
+ const entityIds = res.records.map(r => r.entityId).filter((v, i) => v && res.records.indexOf(v) === i);
3169
+ ClearCacheByEntityIds(api, entityIds);
3170
+ }
3171
+ return res;
3172
+ });
3173
+ }
3174
+ EntityHistoricData.Update = Update;
3175
+ /**
3176
+ * Deletes historic data records for an array of Entity IDs.
3177
+ * This deletes all records within a provided key + range.
3178
+ * @param params
3179
+ * @returns
3180
+ */
3181
+ function Delete(params) {
3182
+ return __awaiter(this, void 0, void 0, function* () {
3183
+ let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
3184
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3185
+ return;
3186
+ }
3187
+ if (!api) {
3188
+ api = ENVIRONMENT.Api().GetBruceApi();
3189
+ }
3190
+ if (!attrKey || !dateTimeFrom || !dateTimeTo) {
3191
+ throw new Error("Invalid parameters provided.");
3192
+ }
3193
+ if (typeof attrKey != "string") {
3194
+ attrKey = PathUtils.Wrap(attrKey);
3195
+ }
3196
+ const urlParams = new URLSearchParams();
3197
+ for (const entityId of entityIds) {
3198
+ urlParams.append("entityId", entityId);
3199
+ }
3200
+ urlParams.append("attrKey", attrKey);
3201
+ urlParams.append("dateTimeFrom", dateTimeFrom);
3202
+ urlParams.append("dateTimeTo", dateTimeTo);
3203
+ yield api.DELETE(`v1/entity/historicData?${urlParams.toString()}`, Api.PrepReqParams(req));
3204
+ // Kill cache for all Entity cached Entity records related to the attrKey.
3205
+ api.Cache.RemoveByContains(Entity.GetHistoricContainsKey(attrKey));
3206
+ // Kill any stats cache that includes any of the Entity IDs.
3207
+ ClearCacheByEntityIds(api, entityIds);
3208
+ });
3209
+ }
3210
+ EntityHistoricData.Delete = Delete;
3211
+ function GetListCacheKey(entityIds, attrKey, dateTimeFrom, dateTimeTo) {
3212
+ return Api.ECacheKey.EntityHistoricDataRec + Api.ECacheKey.Id + entityIds.join(",") + Api.ECacheKey.Id + attrKey + Api.ECacheKey.Id + dateTimeFrom + Api.ECacheKey.Id + dateTimeTo;
3213
+ }
3214
+ EntityHistoricData.GetListCacheKey = GetListCacheKey;
3215
+ function GetStatsCacheKey(entityIds) {
3216
+ return Api.ECacheKey.EntityHistoricDataStats + Api.ECacheKey.Id + entityIds.join(",");
3217
+ }
3218
+ EntityHistoricData.GetStatsCacheKey = GetStatsCacheKey;
3219
+ function ClearCacheByEntityIds(api, entityIds) {
3220
+ if (!api || !(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
3221
+ return;
3222
+ }
3223
+ const REC_KEY_PREFIX = Api.ECacheKey.EntityHistoricDataRec + Api.ECacheKey.Id;
3224
+ const STATS_KEY_PREFIX = Api.ECacheKey.EntityHistoricDataStats + Api.ECacheKey.Id;
3225
+ api.Cache.RemoveByCallback((key) => {
3226
+ let keyStr = String(key);
3227
+ if (!keyStr.startsWith(STATS_KEY_PREFIX) && !keyStr.startsWith(REC_KEY_PREFIX)) {
3228
+ return false;
3229
+ }
3230
+ // Shorten to speed up the next step.
3231
+ keyStr = keyStr.replace(STATS_KEY_PREFIX, "").replace(REC_KEY_PREFIX, "");
3232
+ // Look for any matching Entity IDs.
3233
+ for (let i = 0; i < entityIds.length; i++) {
3234
+ const entityId = entityIds[i];
3235
+ if (keyStr.includes(entityId)) {
3236
+ return true;
3237
+ }
3238
+ }
3239
+ return false;
3240
+ });
3241
+ }
3242
+ EntityHistoricData.ClearCacheByEntityIds = ClearCacheByEntityIds;
3243
+ })(EntityHistoricData || (EntityHistoricData = {}));
3244
+
3044
3245
  /**
3045
3246
  * Describes the "Entity" concept within Nextspace.
3046
3247
  * An entity is a JSON blob containing both internal data and user-defined data.
@@ -3242,6 +3443,7 @@ var Entity;
3242
3443
  }
3243
3444
  yield api.DELETE(`entity/${entityId}`, Api.PrepReqParams(reqParams));
3244
3445
  api.Cache.RemoveByContains(GetContainsKey(entityId));
3446
+ EntityHistoricData.ClearCacheByEntityIds(api, [entityId]);
3245
3447
  });
3246
3448
  }
3247
3449
  Entity.Delete = Delete;
@@ -3265,6 +3467,7 @@ var Entity;
3265
3467
  const entityId = entityIds[i];
3266
3468
  api.Cache.RemoveByContains(GetContainsKey(entityId));
3267
3469
  }
3470
+ EntityHistoricData.ClearCacheByEntityIds(api, entityIds);
3268
3471
  });
3269
3472
  }
3270
3473
  Entity.DeleteList = DeleteList;
@@ -3289,6 +3492,7 @@ var Entity;
3289
3492
  const reqUrl = `entity/${data.Bruce.ID}/?dataoverride=${override}&BruceEntityType=${data.Bruce["EntityType.ID"]}`;
3290
3493
  const res = yield api.POST(reqUrl, data, Api.PrepReqParams(reqParams));
3291
3494
  api.Cache.RemoveByContains(GetContainsKey(data.Bruce.ID));
3495
+ EntityHistoricData.ClearCacheByEntityIds(api, [data.Bruce.ID]);
3292
3496
  return {
3293
3497
  entity: res
3294
3498
  };
@@ -6814,131 +7018,6 @@ var EntityAttribute;
6814
7018
  EntityAttribute.AddAttribute = AddAttribute;
6815
7019
  })(EntityAttribute || (EntityAttribute = {}));
6816
7020
 
6817
- var EntityHistoricData;
6818
- (function (EntityHistoricData) {
6819
- /**
6820
- * Returns historic data for an array of Entity IDs.
6821
- * A maximum number of records will be returned per Entity ID, this information is returned in the response.
6822
- * @param params
6823
- * @returns
6824
- */
6825
- function GetList(params) {
6826
- return __awaiter(this, void 0, void 0, function* () {
6827
- let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
6828
- // Save time and just return a none response if no entity IDs are provided.
6829
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6830
- return {
6831
- limitPerEntity: 0,
6832
- recordsByIds: {}
6833
- };
6834
- }
6835
- if (!api) {
6836
- api = ENVIRONMENT.Api().GetBruceApi();
6837
- }
6838
- if (typeof attrKey != "string") {
6839
- attrKey = PathUtils.Wrap(attrKey);
6840
- }
6841
- const urlParams = new URLSearchParams();
6842
- for (const entityId of entityIds) {
6843
- urlParams.append("entityId", entityId);
6844
- }
6845
- urlParams.append("attrKey", attrKey);
6846
- urlParams.append("dateTimeFrom", dateTimeFrom);
6847
- urlParams.append("dateTimeTo", dateTimeTo);
6848
- return yield api.GET(`v1/entity/historicData?${urlParams.toString()}`, Api.PrepReqParams(req));
6849
- });
6850
- }
6851
- EntityHistoricData.GetList = GetList;
6852
- /**
6853
- * Returns historic data statistics for an array of Entity IDs.
6854
- * @param params
6855
- * @returns
6856
- */
6857
- function GetStats(params) {
6858
- return __awaiter(this, void 0, void 0, function* () {
6859
- let { entityIds, api, req } = params;
6860
- // Save time and just return a none response if no entity IDs are provided.
6861
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6862
- return {
6863
- stats: []
6864
- };
6865
- }
6866
- if (!api) {
6867
- api = ENVIRONMENT.Api().GetBruceApi();
6868
- }
6869
- return yield api.POST("v1/entity/historicData/stats", {
6870
- entityIds: entityIds
6871
- }, Api.PrepReqParams(req));
6872
- });
6873
- }
6874
- EntityHistoricData.GetStats = GetStats;
6875
- /**
6876
- * Creates or updates historic data records.
6877
- * Please note that the expected input/output does not include internal fields found inside the "Bruce" attribute.
6878
- * @param params
6879
- * @returns
6880
- */
6881
- function Update(params) {
6882
- return __awaiter(this, void 0, void 0, function* () {
6883
- let { records, api, req } = params;
6884
- // Save time and just return a none response if no records are provided.
6885
- if (!(records === null || records === void 0 ? void 0 : records.length)) {
6886
- return {
6887
- records: []
6888
- };
6889
- }
6890
- if (!api) {
6891
- api = ENVIRONMENT.Api().GetBruceApi();
6892
- }
6893
- const res = yield api.POST("v1/entity/historicData", {
6894
- records: records
6895
- }, Api.PrepReqParams(req));
6896
- // Kill cache for every unique attrKey.
6897
- let attrKeys = records.map(r => r.attrKey);
6898
- attrKeys = attrKeys.filter((v, i) => attrKeys.indexOf(v) === i);
6899
- for (const attrKey of attrKeys) {
6900
- api.Cache.RemoveByContains(Entity.GetHistoricContainsKey(attrKey));
6901
- }
6902
- return res;
6903
- });
6904
- }
6905
- EntityHistoricData.Update = Update;
6906
- /**
6907
- * Deletes historic data records for an array of Entity IDs.
6908
- * This deletes all records within a provided key + range.
6909
- * @param params
6910
- * @returns
6911
- */
6912
- function Delete(params) {
6913
- return __awaiter(this, void 0, void 0, function* () {
6914
- let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
6915
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6916
- return;
6917
- }
6918
- if (!api) {
6919
- api = ENVIRONMENT.Api().GetBruceApi();
6920
- }
6921
- if (!attrKey || !dateTimeFrom || !dateTimeTo) {
6922
- throw new Error("Invalid parameters provided.");
6923
- }
6924
- if (typeof attrKey != "string") {
6925
- attrKey = PathUtils.Wrap(attrKey);
6926
- }
6927
- const urlParams = new URLSearchParams();
6928
- for (const entityId of entityIds) {
6929
- urlParams.append("entityId", entityId);
6930
- }
6931
- urlParams.append("attrKey", attrKey);
6932
- urlParams.append("dateTimeFrom", dateTimeFrom);
6933
- urlParams.append("dateTimeTo", dateTimeTo);
6934
- yield api.DELETE(`v1/entity/historicData?${urlParams.toString()}`, Api.PrepReqParams(req));
6935
- // Kill cache for all Entity cached Entity records related to the attrKey.
6936
- api.Cache.RemoveByContains(Entity.GetHistoricContainsKey(attrKey));
6937
- });
6938
- }
6939
- EntityHistoricData.Delete = Delete;
6940
- })(EntityHistoricData || (EntityHistoricData = {}));
6941
-
6942
7021
  /**
6943
7022
  * Utility for uploading files.
6944
7023
  */
@@ -11430,7 +11509,7 @@ var DataSource;
11430
11509
  })(DataSource || (DataSource = {}));
11431
11510
 
11432
11511
  // This is updated with the package.json version on build.
11433
- const VERSION = "3.9.2";
11512
+ const VERSION = "3.9.4";
11434
11513
 
11435
11514
  export { VERSION, AnnDocument, CustomForm, AbstractApi, Api, BruceApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityCoords, EntityTypeVisualSettings, EntityAttribute, EntityHistoricData, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, ProjectViewLegacy, ProjectViewLegacyBookmark, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, AccountFeatures, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT, DataSource };
11436
11515
  //# sourceMappingURL=bruce-models.es5.js.map