bruce-models 3.0.5 → 3.0.7

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.
@@ -2016,11 +2016,12 @@
2016
2016
  })(exports.PathUtils || (exports.PathUtils = {}));
2017
2017
 
2018
2018
  (function (Entity) {
2019
- function GetCacheKey(entityId, entityTypeId, expandLocation) {
2019
+ function GetCacheKey(params) {
2020
+ let { entityId, entityTypeId, expandLocation, expandRelations } = params;
2020
2021
  if (!entityTypeId) {
2021
2022
  entityTypeId = "";
2022
2023
  }
2023
- return `${exports.Api.ECacheKey.Entity}${exports.Api.ECacheKey.Id}${entityId}${String(entityTypeId)}${String(Boolean(expandLocation))}`;
2024
+ return `${exports.Api.ECacheKey.Entity}${exports.Api.ECacheKey.Id}${entityId}${String(entityTypeId)}${String(Boolean(expandLocation))}${String(Boolean(expandRelations))}`;
2024
2025
  }
2025
2026
  Entity.GetCacheKey = GetCacheKey;
2026
2027
  function GetContainsKey(entityId) {
@@ -2029,15 +2030,20 @@
2029
2030
  Entity.GetContainsKey = GetContainsKey;
2030
2031
  function Get(params) {
2031
2032
  return __awaiter(this, void 0, void 0, function* () {
2032
- let { api, entityId, req: reqParams, expandLocation, entityTypeId } = params;
2033
+ let { api, entityId, req: reqParams, expandLocation, expandRelations, entityTypeId } = params;
2033
2034
  if (!api) {
2034
2035
  api = exports.ENVIRONMENT.Api().GetBruceApi();
2035
2036
  }
2036
2037
  if (!entityId) {
2037
2038
  throw ("Entity ID is required.");
2038
2039
  }
2039
- const key = GetCacheKey(entityId, entityTypeId, expandLocation);
2040
- const cache = yield api.GetCacheItem(key, reqParams);
2040
+ const key = GetCacheKey({
2041
+ entityId,
2042
+ entityTypeId,
2043
+ expandLocation,
2044
+ expandRelations
2045
+ });
2046
+ const cache = api.GetCacheItem(key, reqParams);
2041
2047
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
2042
2048
  return cache.data;
2043
2049
  }
@@ -2047,6 +2053,9 @@
2047
2053
  if (expandLocation) {
2048
2054
  urlParams.append("$expand", "location");
2049
2055
  }
2056
+ if (expandRelations) {
2057
+ urlParams.append("$expand", "relation");
2058
+ }
2050
2059
  if (entityTypeId) {
2051
2060
  urlParams.append("BruceEntityType", entityTypeId);
2052
2061
  }
@@ -2059,7 +2068,7 @@
2059
2068
  rej(e);
2060
2069
  }
2061
2070
  }));
2062
- yield api.SetCacheItem({
2071
+ api.SetCacheItem({
2063
2072
  key,
2064
2073
  value: prom,
2065
2074
  req: reqParams
@@ -2070,7 +2079,7 @@
2070
2079
  Entity.Get = Get;
2071
2080
  function GetListByIds(params) {
2072
2081
  return __awaiter(this, void 0, void 0, function* () {
2073
- let { api, entityIds, req: reqParams } = params;
2082
+ let { api, entityIds, req: reqParams, expandRelations } = params;
2074
2083
  if (!api) {
2075
2084
  api = exports.ENVIRONMENT.Api().GetBruceApi();
2076
2085
  }
@@ -2081,8 +2090,8 @@
2081
2090
  const reqIds = [];
2082
2091
  for (let i = 0; i < entityIds.length; i++) {
2083
2092
  const entityId = entityIds[i];
2084
- const key = GetCacheKey(entityId);
2085
- const cache = yield api.GetCacheItem(key, reqParams);
2093
+ const key = GetCacheKey({ entityId, expandRelations });
2094
+ const cache = api.GetCacheItem(key, reqParams);
2086
2095
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
2087
2096
  reqs.push(cache.data);
2088
2097
  }
@@ -2099,10 +2108,14 @@
2099
2108
  PageSize: reqIds.length
2100
2109
  };
2101
2110
  if (reqIds.length > 0) {
2102
- const req = api.POST("entities", reqData, exports.Api.PrepReqParams(reqParams));
2111
+ const urlParams = new URLSearchParams();
2112
+ if (expandRelations) {
2113
+ urlParams.append("$expand", "relation");
2114
+ }
2115
+ const req = api.POST("entities?" + urlParams.toString(), reqData, exports.Api.PrepReqParams(reqParams));
2103
2116
  for (let i = 0; i < reqIds.length; i++) {
2104
2117
  const entityId = reqIds[i];
2105
- const key = GetCacheKey(entityId);
2118
+ const key = GetCacheKey({ entityId });
2106
2119
  const prom = new Promise((res) => __awaiter(this, void 0, void 0, function* () {
2107
2120
  try {
2108
2121
  const data = yield req;
@@ -2116,7 +2129,7 @@
2116
2129
  }
2117
2130
  res(null);
2118
2131
  }));
2119
- yield api.SetCacheItem({
2132
+ api.SetCacheItem({
2120
2133
  key,
2121
2134
  value: prom,
2122
2135
  req: reqParams
@@ -2273,7 +2286,7 @@
2273
2286
  function GetList(params) {
2274
2287
  var _a;
2275
2288
  return __awaiter(this, void 0, void 0, function* () {
2276
- let { api, filter, req: reqParams, viaCdn, viaCdnCacheToken, analysis } = params;
2289
+ let { api, filter, req: reqParams, viaCdn, viaCdnCacheToken, analysis, expandRelations } = params;
2277
2290
  if (!api) {
2278
2291
  api = exports.ENVIRONMENT.Api().GetBruceApi();
2279
2292
  }
@@ -2308,12 +2321,17 @@
2308
2321
  };
2309
2322
  let totalCount;
2310
2323
  let entities = [];
2311
- if (analysis || (viaCdn && api.EntityCdnUrl)) {
2312
- const url = new URL(
2313
- // !analysis && viaCdn... for now because we have an inflexible CDN param in the lib.
2314
- // Api CAN support this. TODO: Have a CDN base url instead of an EntityCDN base url.
2315
- (!analysis && viaCdn && api.EntityCdnUrl) ? api.EntityCdnUrl :
2316
- (api.GetBaseUrl() + (analysis ? "entities/summary" : "entities")));
2324
+ if (analysis || expandRelations || (viaCdn && api.EntityCdnUrl)) {
2325
+ let url;
2326
+ if (analysis) {
2327
+ url = new URL(api.GetBaseUrl() + "entities/summary");
2328
+ }
2329
+ else if (viaCdn && api.EntityCdnUrl) {
2330
+ url = new URL(api.EntityCdnUrl);
2331
+ }
2332
+ else {
2333
+ url = new URL(api.GetBaseUrl() + "entities");
2334
+ }
2317
2335
  const urlParams = new URLSearchParams(url.search);
2318
2336
  urlParams.set("cacheToken", String(viaCdnCacheToken ? viaCdnCacheToken : 0));
2319
2337
  if (body.SortOrder) {
@@ -2337,6 +2355,9 @@
2337
2355
  if (body.PageSize) {
2338
2356
  urlParams.set("PageSize", String(body.PageSize));
2339
2357
  }
2358
+ if (expandRelations) {
2359
+ urlParams.append("$expand", "relation");
2360
+ }
2340
2361
  const urlStr = url.toString() + "?" + urlParams.toString();
2341
2362
  const data = yield api.get(urlStr, exports.Api.PrepReqParams(reqParams));
2342
2363
  if (!analysis) {
@@ -2345,15 +2366,24 @@
2345
2366
  totalCount = data.TotalCount;
2346
2367
  }
2347
2368
  else {
2348
- const data = yield api.POST(analysis ? "entities/summary" : "entities", body, exports.Api.PrepReqParams(reqParams));
2369
+ const url = new URL(api.GetBaseUrl() + (analysis ? "entities/summary" : "entities"));
2370
+ const urlParams = new URLSearchParams(url.search);
2371
+ if (expandRelations) {
2372
+ urlParams.append("$expand", "relation");
2373
+ }
2374
+ const urlStr = url.toString() + "?" + urlParams.toString();
2375
+ const data = yield api.post(urlStr, body, exports.Api.PrepReqParams(reqParams));
2349
2376
  if (!analysis) {
2350
2377
  entities = data.Items;
2351
2378
  // Only caching when non-CDN.
2352
2379
  for (let i = 0; i < entities.length; i++) {
2353
2380
  const entity = entities[i];
2354
2381
  const id = entity.Bruce.ID;
2355
- yield api.SetCacheItem({
2356
- key: GetCacheKey(id),
2382
+ api.SetCacheItem({
2383
+ key: GetCacheKey({
2384
+ entityId: id,
2385
+ expandRelations
2386
+ }),
2357
2387
  value: {
2358
2388
  entity: entity
2359
2389
  },
@@ -6425,7 +6455,9 @@
6425
6455
  EType["PointCloud"] = "PointCloudTileset";
6426
6456
  EType["EntitiesLoaded"] = "LoadedEntities";
6427
6457
  EType["EntitiesIds"] = "EntitiesIds";
6458
+ // Deprecated. Use Relationships instead.
6428
6459
  EType["Relations"] = "Relations";
6460
+ EType["Relationships"] = "Relationships";
6429
6461
  EType["GooglePhotoTileset"] = "GooglePhotoTileset";
6430
6462
  })(EType = MenuItem.EType || (MenuItem.EType = {}));
6431
6463
  function CreateFromEntityId(entityId, typeId, styleId) {
@@ -6514,9 +6546,6 @@
6514
6546
  throw ("Tileset type not supported.");
6515
6547
  }
6516
6548
  MenuItem.CreateFromTilesetId = CreateFromTilesetId;
6517
- let Item;
6518
- (function (Item) {
6519
- })(Item = MenuItem.Item || (MenuItem.Item = {}));
6520
6549
  })(exports.MenuItem || (exports.MenuItem = {}));
6521
6550
 
6522
6551
  (function (ProjectViewBookmark) {
@@ -8905,7 +8934,7 @@
8905
8934
  DataSource.GetList = GetList;
8906
8935
  })(exports.DataSource || (exports.DataSource = {}));
8907
8936
 
8908
- const VERSION = "3.0.5";
8937
+ const VERSION = "3.0.7";
8909
8938
 
8910
8939
  exports.VERSION = VERSION;
8911
8940
  exports.AbstractApi = AbstractApi;