bruce-models 7.1.40 → 7.1.42

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.
@@ -8869,19 +8869,46 @@
8869
8869
  */
8870
8870
  function GetEntityCoords(params) {
8871
8871
  return __awaiter(this, void 0, void 0, function* () {
8872
- let { api, rootEntityId: entityId, req: reqParams } = params;
8872
+ let { api, rootEntityId, req: reqParams } = params;
8873
8873
  if (!api) {
8874
8874
  api = exports.ENVIRONMENT.Api().GetBruceApi();
8875
8875
  }
8876
- const cache = api.GetCacheItem(GetCacheKey(entityId), reqParams);
8876
+ const entityIds = (Array.isArray(rootEntityId) ? rootEntityId : [rootEntityId]).filter(id => !!id);
8877
+ if (!entityIds.length) {
8878
+ throw ("Root Entity ID is required.");
8879
+ }
8880
+ const cacheKey = GetCacheKey(Array.isArray(rootEntityId) ? entityIds : entityIds[0]);
8881
+ const cache = api.GetCacheItem(cacheKey, reqParams);
8877
8882
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
8878
8883
  return cache.data;
8879
8884
  }
8880
8885
  const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
8886
+ var _a;
8881
8887
  try {
8882
- const data = yield api.GET(`entity/${entityId}/ucs`, reqParams);
8888
+ if (entityIds.length == 1) {
8889
+ const data = yield api.GET(`entity/${entityIds[0]}/ucs`, reqParams);
8890
+ res({
8891
+ coords: data,
8892
+ coordsMap: {
8893
+ [entityIds[0]]: data
8894
+ }
8895
+ });
8896
+ return;
8897
+ }
8898
+ const data = yield api.GET(`entity/ucs?rootId=${entityIds.map(encodeURIComponent).join(",")}`, reqParams);
8899
+ const coords = (_a = data === null || data === void 0 ? void 0 : data.Items) === null || _a === void 0 ? void 0 : _a[0];
8900
+ if (!coords) {
8901
+ throw ("No Entity coordinates found.");
8902
+ }
8903
+ const coordsMap = {};
8904
+ for (const item of data.Items || []) {
8905
+ if (item === null || item === void 0 ? void 0 : item["Entity.ID"]) {
8906
+ coordsMap[item["Entity.ID"]] = item;
8907
+ }
8908
+ }
8883
8909
  res({
8884
- coords: data
8910
+ coords,
8911
+ coordsMap
8885
8912
  });
8886
8913
  }
8887
8914
  catch (e) {
@@ -8889,7 +8916,7 @@
8889
8916
  }
8890
8917
  }));
8891
8918
  api.SetCacheItem({
8892
- key: GetCacheKey(entityId),
8919
+ key: cacheKey,
8893
8920
  value: prom,
8894
8921
  req: reqParams
8895
8922
  });
@@ -8933,7 +8960,7 @@
8933
8960
  "test": params.test
8934
8961
  }, reqParams);
8935
8962
  if (!params.test) {
8936
- api.Cache.Remove(GetCacheKey(entityId));
8963
+ InvalidateCoordsCache(api, entityId);
8937
8964
  }
8938
8965
  return {
8939
8966
  coords: res
@@ -8980,7 +9007,7 @@
8980
9007
  "test": params.test
8981
9008
  }, reqParams);
8982
9009
  if (!params.test) {
8983
- api.Cache.Remove(GetCacheKey(entityId));
9010
+ InvalidateCoordsCache(api, entityId);
8984
9011
  }
8985
9012
  return {
8986
9013
  coords: res
@@ -9014,7 +9041,7 @@
9014
9041
  "test": params.test
9015
9042
  }, reqParams);
9016
9043
  if (!params.test) {
9017
- api.Cache.Remove(GetCacheKey(entityId));
9044
+ InvalidateCoordsCache(api, entityId);
9018
9045
  }
9019
9046
  return {
9020
9047
  coords: res
@@ -9033,7 +9060,8 @@
9033
9060
  if (!api) {
9034
9061
  api = exports.ENVIRONMENT.Api().GetBruceApi();
9035
9062
  }
9036
- return api.DELETE(`entity/${entityId}/ucs`, reqParams);
9063
+ yield api.DELETE(`entity/${entityId}/ucs`, reqParams);
9064
+ InvalidateCoordsCache(api, entityId);
9037
9065
  });
9038
9066
  }
9039
9067
  EntityCoords.UnlinkCoords = UnlinkCoords;
@@ -9048,9 +9076,36 @@
9048
9076
  * @returns
9049
9077
  */
9050
9078
  function GetCacheKey(entityId) {
9051
- return exports.Api.ECacheKey.EntityCoords + exports.Api.ECacheKey.Entity + exports.Api.ECacheKey.Id + entityId;
9079
+ const isList = Array.isArray(entityId);
9080
+ const id = isList ? entityId.join(",") : entityId;
9081
+ return exports.Api.ECacheKey.EntityCoords + exports.Api.ECacheKey.Entity + (isList ? exports.Api.ECacheKey.ListId : exports.Api.ECacheKey.Id) + id;
9052
9082
  }
9053
9083
  EntityCoords.GetCacheKey = GetCacheKey;
9084
+ /**
9085
+ * Invalidates all cached coords that involve the given Entity ID.
9086
+ *
9087
+ * Example:
9088
+ * ```
9089
+ * const api: BruceApi.Api = ...;
9090
+ * InvalidateCoordsCache(api, "123");
9091
+ * ```
9092
+ * @param api
9093
+ * @param entityId Single Entity whose cached coords should be invalidated.
9094
+ */
9095
+ function InvalidateCoordsCache(api, entityId) {
9096
+ // Remove the exact single-entity cache entry.
9097
+ api.Cache.Remove(GetCacheKey(entityId));
9098
+ // Remove any multi-Entity cache entries whose ID list includes this Entity.
9099
+ const multiPrefix = exports.Api.ECacheKey.EntityCoords + exports.Api.ECacheKey.Entity + exports.Api.ECacheKey.ListId;
9100
+ api.Cache.RemoveBy(key => {
9101
+ const k = String(key);
9102
+ if (!k.startsWith(multiPrefix)) {
9103
+ return false;
9104
+ }
9105
+ return k.slice(multiPrefix.length).split(",").includes(entityId);
9106
+ });
9107
+ }
9108
+ EntityCoords.InvalidateCoordsCache = InvalidateCoordsCache;
9054
9109
  })(exports.EntityCoords || (exports.EntityCoords = {}));
9055
9110
 
9056
9111
  (function (EntityTableView) {
@@ -18175,7 +18230,7 @@
18175
18230
  })(exports.ChangeSet || (exports.ChangeSet = {}));
18176
18231
 
18177
18232
  // This is updated with the package.json version on build.
18178
- const VERSION = "7.1.40";
18233
+ const VERSION = "7.1.42";
18179
18234
 
18180
18235
  exports.VERSION = VERSION;
18181
18236
  exports.AbstractApi = AbstractApi;