bruce-models 3.8.4 → 3.8.6

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.
@@ -77,6 +77,7 @@
77
77
  ECacheKey["ImportedFile"] = "importedfile";
78
78
  ECacheKey["Plugin"] = "plugin";
79
79
  ECacheKey["PluginIndexFile"] = "pluginindexfile";
80
+ ECacheKey["EntityHistoricData"] = "entityhistoricdata";
80
81
  })(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
81
82
  // 1 minute.
82
83
  Api.DEFAULT_CACHE_DURATION = 60 * 1000;
@@ -2819,6 +2820,53 @@
2819
2820
  });
2820
2821
  }
2821
2822
  EntityType.Update = Update;
2823
+ /**
2824
+ * Starts a re-index background action on a specified Entity Type.
2825
+ * This will ensure searchable data follows the current schema version.
2826
+ * This will also perform certain data cleanup so that the data is consistent.
2827
+ * @param params
2828
+ * @returns
2829
+ */
2830
+ function ReIndex(params) {
2831
+ return __awaiter(this, void 0, void 0, function* () {
2832
+ let { api, entityTypeId: typeId, req } = params;
2833
+ if (!typeId) {
2834
+ throw ("Type ID is required.");
2835
+ }
2836
+ if (!api) {
2837
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
2838
+ }
2839
+ const urlParams = new URLSearchParams();
2840
+ if (params.dataTransformId) {
2841
+ urlParams.append("dataTransformID", String(params.dataTransformId));
2842
+ }
2843
+ const url = `entitytype/${typeId}/reindex?${urlParams.toString()}`;
2844
+ req = exports.Api.PrepReqParams(req);
2845
+ const pa = yield api.POST(url, {}, req);
2846
+ return pa;
2847
+ });
2848
+ }
2849
+ EntityType.ReIndex = ReIndex;
2850
+ /**
2851
+ * Counts the total number of Entities in an Entity Type.
2852
+ * @param params
2853
+ * @returns
2854
+ */
2855
+ function Count(params) {
2856
+ return __awaiter(this, void 0, void 0, function* () {
2857
+ let { entityTypeId, api, req } = params;
2858
+ if (!entityTypeId) {
2859
+ throw ("Type ID is required.");
2860
+ }
2861
+ if (!api) {
2862
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
2863
+ }
2864
+ const url = `entityType/${entityTypeId}/entitiesCount`;
2865
+ const { TotalEntities } = yield api.GET(url, exports.Api.PrepReqParams(req));
2866
+ return TotalEntities;
2867
+ });
2868
+ }
2869
+ EntityType.Count = Count;
2822
2870
  /**
2823
2871
  * Returns cache identifier for an entity type.
2824
2872
  * Example: {
@@ -2950,7 +2998,7 @@
2950
2998
  */
2951
2999
  function Get(params) {
2952
3000
  return __awaiter(this, void 0, void 0, function* () {
2953
- let { api, entityId, req: reqParams, expandLocation, expandRelations, entityTypeId } = params;
3001
+ let { api, entityId, req: reqParams, expandLocation, expandRelations, entityTypeId, historicFrom, historicKey, historicTo } = params;
2954
3002
  if (!entityId) {
2955
3003
  throw ("Entity ID is required.");
2956
3004
  }
@@ -2961,7 +3009,10 @@
2961
3009
  entityId,
2962
3010
  entityTypeId,
2963
3011
  expandLocation,
2964
- expandRelations
3012
+ expandRelations,
3013
+ historicFrom,
3014
+ historicKey,
3015
+ historicTo
2965
3016
  });
2966
3017
  const cache = api.GetCacheItem(key, reqParams);
2967
3018
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
@@ -3004,7 +3055,7 @@
3004
3055
  */
3005
3056
  function GetListByIds(params) {
3006
3057
  return __awaiter(this, void 0, void 0, function* () {
3007
- let { api, entityIds, req: reqParams, expandRelations, expandLocation } = params;
3058
+ let { api, entityIds, req: reqParams, expandRelations, expandLocation, historicFrom, historicKey, historicTo } = params;
3008
3059
  if (!entityIds.length) {
3009
3060
  throw ("Entity IDs are required.");
3010
3061
  }
@@ -3043,7 +3094,15 @@
3043
3094
  const req = api.POST("entities", reqData, exports.Api.PrepReqParams(reqParams));
3044
3095
  for (let i = 0; i < reqIds.length; i++) {
3045
3096
  const entityId = reqIds[i];
3046
- const key = GetCacheKey({ entityId, expandLocation, expandRelations });
3097
+ const key = GetCacheKey({
3098
+ entityId,
3099
+ expandLocation,
3100
+ expandRelations,
3101
+ entityTypeId: null,
3102
+ historicFrom: historicFrom,
3103
+ historicKey: historicKey,
3104
+ historicTo: historicTo
3105
+ });
3047
3106
  const prom = new Promise((res) => __awaiter(this, void 0, void 0, function* () {
3048
3107
  try {
3049
3108
  const data = yield req;
@@ -3324,7 +3383,7 @@
3324
3383
  function GetList(params) {
3325
3384
  var _a;
3326
3385
  return __awaiter(this, void 0, void 0, function* () {
3327
- let { api, filter, req: reqParams, viaCdn, viaCdnCacheToken, analysis, expandRelations } = params;
3386
+ let { api, filter, req: reqParams, viaCdn, viaCdnCacheToken, analysis, expandRelations, historicFrom, historicKey, historicTo } = params;
3328
3387
  if (!api) {
3329
3388
  api = exports.ENVIRONMENT.Api().GetBruceApi();
3330
3389
  }
@@ -3425,7 +3484,12 @@
3425
3484
  api.SetCacheItem({
3426
3485
  key: GetCacheKey({
3427
3486
  entityId: id,
3428
- expandRelations
3487
+ expandRelations,
3488
+ expandLocation: false,
3489
+ entityTypeId: filter.entityTypeId,
3490
+ historicFrom: historicFrom,
3491
+ historicKey: historicKey,
3492
+ historicTo: historicTo
3429
3493
  }),
3430
3494
  value: {
3431
3495
  entity: entity
@@ -3573,11 +3637,23 @@
3573
3637
  * @returns
3574
3638
  */
3575
3639
  function GetCacheKey(params) {
3576
- let { entityId, entityTypeId, expandLocation, expandRelations } = params;
3640
+ let { entityId, entityTypeId, expandLocation, expandRelations, historicFrom, historicKey, historicTo } = params;
3577
3641
  if (!entityTypeId) {
3578
3642
  entityTypeId = "";
3579
3643
  }
3580
- return `${exports.Api.ECacheKey.Entity}${exports.Api.ECacheKey.Id}${entityId}${String(entityTypeId)}${String(Boolean(expandLocation))}${String(Boolean(expandRelations))}`;
3644
+ if (!historicKey) {
3645
+ historicKey = "";
3646
+ }
3647
+ if (!historicFrom) {
3648
+ historicFrom = "";
3649
+ }
3650
+ if (!historicTo) {
3651
+ historicTo = "";
3652
+ }
3653
+ let key = `${exports.Api.ECacheKey.Entity}${exports.Api.ECacheKey.Id}${entityId}${String(entityTypeId)}`;
3654
+ key += `${String(Boolean(expandLocation))}${String(Boolean(expandRelations))}`;
3655
+ key += `${exports.Api.ECacheKey.EntityHistoricData}${exports.Api.ECacheKey.Id}${historicKey}${historicFrom}${historicTo}`;
3656
+ return key;
3581
3657
  }
3582
3658
  Entity.GetCacheKey = GetCacheKey;
3583
3659
  /**
@@ -3594,6 +3670,18 @@
3594
3670
  return `${exports.Api.ECacheKey.Entity}${exports.Api.ECacheKey.Id}${entityId}`;
3595
3671
  }
3596
3672
  Entity.GetContainsKey = GetContainsKey;
3673
+ /**
3674
+ * Returns cache identifier for entity records that have historic data.
3675
+ * @param attrKey
3676
+ * @returns
3677
+ */
3678
+ function GetHistoricContainsKey(attrKey) {
3679
+ if (!attrKey) {
3680
+ attrKey = "";
3681
+ }
3682
+ return `${exports.Api.ECacheKey.EntityHistoricData}${exports.Api.ECacheKey.Id}${attrKey}`;
3683
+ }
3684
+ Entity.GetHistoricContainsKey = GetHistoricContainsKey;
3597
3685
  })(exports.Entity || (exports.Entity = {}));
3598
3686
 
3599
3687
  /**
@@ -6540,6 +6628,130 @@
6540
6628
  EntityAttribute.AddAttribute = AddAttribute;
6541
6629
  })(exports.EntityAttribute || (exports.EntityAttribute = {}));
6542
6630
 
6631
+ (function (EntityHistoricData) {
6632
+ /**
6633
+ * Returns historic data for an array of Entity IDs.
6634
+ * A maximum number of records will be returned per Entity ID, this information is returned in the response.
6635
+ * @param params
6636
+ * @returns
6637
+ */
6638
+ function GetList(params) {
6639
+ return __awaiter(this, void 0, void 0, function* () {
6640
+ let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
6641
+ // Save time and just return a none response if no entity IDs are provided.
6642
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6643
+ return {
6644
+ limitPerEntity: 0,
6645
+ recordsByIds: {}
6646
+ };
6647
+ }
6648
+ if (!api) {
6649
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
6650
+ }
6651
+ if (typeof attrKey != "string") {
6652
+ attrKey = exports.PathUtils.Wrap(attrKey);
6653
+ }
6654
+ const urlParams = new URLSearchParams();
6655
+ for (const entityId of entityIds) {
6656
+ urlParams.append("entityId", entityId);
6657
+ }
6658
+ urlParams.append("attrKey", attrKey);
6659
+ urlParams.append("dateTimeFrom", dateTimeFrom);
6660
+ urlParams.append("dateTimeTo", dateTimeTo);
6661
+ return yield api.GET(`v1/entity/historicData?${urlParams.toString()}`, exports.Api.PrepReqParams(req));
6662
+ });
6663
+ }
6664
+ EntityHistoricData.GetList = GetList;
6665
+ /**
6666
+ * Returns historic data statistics for an array of Entity IDs.
6667
+ * @param params
6668
+ * @returns
6669
+ */
6670
+ function GetStats(params) {
6671
+ return __awaiter(this, void 0, void 0, function* () {
6672
+ let { entityIds, api, req } = params;
6673
+ // Save time and just return a none response if no entity IDs are provided.
6674
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6675
+ return {
6676
+ stats: []
6677
+ };
6678
+ }
6679
+ if (!api) {
6680
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
6681
+ }
6682
+ return yield api.POST("v1/entity/historicData/stats", {
6683
+ entityIds: entityIds
6684
+ }, exports.Api.PrepReqParams(req));
6685
+ });
6686
+ }
6687
+ EntityHistoricData.GetStats = GetStats;
6688
+ /**
6689
+ * Creates or updates historic data records.
6690
+ * Please note that the expected input/output does not include internal fields found inside the "Bruce" attribute.
6691
+ * @param params
6692
+ * @returns
6693
+ */
6694
+ function Update(params) {
6695
+ return __awaiter(this, void 0, void 0, function* () {
6696
+ let { records, api, req } = params;
6697
+ // Save time and just return a none response if no records are provided.
6698
+ if (!(records === null || records === void 0 ? void 0 : records.length)) {
6699
+ return {
6700
+ records: []
6701
+ };
6702
+ }
6703
+ if (!api) {
6704
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
6705
+ }
6706
+ const res = yield api.POST("v1/entity/historicData", {
6707
+ records: records
6708
+ }, exports.Api.PrepReqParams(req));
6709
+ // Kill cache for every unique attrKey.
6710
+ let attrKeys = records.map(r => r.attrKey);
6711
+ attrKeys = attrKeys.filter((v, i) => attrKeys.indexOf(v) === i);
6712
+ for (const attrKey of attrKeys) {
6713
+ api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
6714
+ }
6715
+ return res;
6716
+ });
6717
+ }
6718
+ EntityHistoricData.Update = Update;
6719
+ /**
6720
+ * Deletes historic data records for an array of Entity IDs.
6721
+ * This deletes all records within a provided key + range.
6722
+ * @param params
6723
+ * @returns
6724
+ */
6725
+ function Delete(params) {
6726
+ return __awaiter(this, void 0, void 0, function* () {
6727
+ let { entityIds, attrKey, dateTimeFrom, dateTimeTo, api, req } = params;
6728
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
6729
+ return;
6730
+ }
6731
+ if (!api) {
6732
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
6733
+ }
6734
+ if (!attrKey || !dateTimeFrom || !dateTimeTo) {
6735
+ throw new Error("Invalid parameters provided.");
6736
+ }
6737
+ if (typeof attrKey != "string") {
6738
+ attrKey = exports.PathUtils.Wrap(attrKey);
6739
+ }
6740
+ const urlParams = new URLSearchParams();
6741
+ for (const entityId of entityIds) {
6742
+ urlParams.append("entityId", entityId);
6743
+ }
6744
+ urlParams.append("attrKey", attrKey);
6745
+ urlParams.append("dateTimeFrom", dateTimeFrom);
6746
+ urlParams.append("dateTimeTo", dateTimeTo);
6747
+ yield api.DELETE(`v1/entity/historicData?${urlParams.toString()}`, exports.Api.PrepReqParams(req));
6748
+ // Kill cache for all Entity cached Entity records related to the attrKey.
6749
+ api.Cache.RemoveByContains(exports.Entity.GetHistoricContainsKey(attrKey));
6750
+ });
6751
+ }
6752
+ EntityHistoricData.Delete = Delete;
6753
+ })(exports.EntityHistoricData || (exports.EntityHistoricData = {}));
6754
+
6543
6755
  (function (Uploader) {
6544
6756
  Uploader.MIN_LARGE_FILE_SIZE = 100000000; // 100MB.
6545
6757
  /**
@@ -9818,6 +10030,8 @@
9818
10030
  EFeature["EntityJsonData"] = "Feature_Entity_JSONData";
9819
10031
  // Flag to enable a text search against JSON data values.
9820
10032
  // 'EntityJsonData' must also be enabled.
10033
+ // @WARNING: Please re-index all Entities first before enabling this feature.
10034
+ // Without this the raw 2D geometry will be indexed which will make it much slower, and may cause the update of the flag to fail.
9821
10035
  EFeature["EntityLexicalSearch"] = "Feature_Entity_Lexical_Search";
9822
10036
  })(EFeature = AccountFeatures.EFeature || (AccountFeatures.EFeature = {}));
9823
10037
  /**
@@ -10908,7 +11122,7 @@
10908
11122
  })(exports.DataSource || (exports.DataSource = {}));
10909
11123
 
10910
11124
  // This is updated with the package.json version on build.
10911
- const VERSION = "3.8.4";
11125
+ const VERSION = "3.8.6";
10912
11126
 
10913
11127
  exports.VERSION = VERSION;
10914
11128
  exports.AbstractApi = AbstractApi;