bruce-models 0.3.0 → 0.3.2

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.
@@ -536,6 +536,37 @@ var AbstractApi = /** @class */ (function () {
536
536
  });
537
537
  });
538
538
  };
539
+ AbstractApi.prototype.put = function (url, data, params) {
540
+ var _a;
541
+ return __awaiter(this, void 0, void 0, function () {
542
+ var res;
543
+ var _b;
544
+ return __generator(this, function (_c) {
545
+ switch (_c.label) {
546
+ case 0:
547
+ if (!params) {
548
+ params = {};
549
+ }
550
+ params.headers = params.headers || {};
551
+ params.headers = __assign((_b = { "Content-Type": "application/json;" }, _b[this.ssidHeader] = this.ssid, _b), params.headers);
552
+ if (!data) {
553
+ data = {};
554
+ }
555
+ if (typeof data != "string") {
556
+ data = JSON.stringify(data);
557
+ }
558
+ return [4 /*yield*/, fetch(url, {
559
+ headers: params.headers,
560
+ method: "PUT",
561
+ body: data
562
+ })];
563
+ case 1:
564
+ res = _c.sent();
565
+ return [2 /*return*/, parseResult(res, (_a = params.response) === null || _a === void 0 ? void 0 : _a.encoding)];
566
+ }
567
+ });
568
+ });
569
+ };
539
570
  AbstractApi.prototype.upload = function (url, blob, params) {
540
571
  return __awaiter(this, void 0, void 0, function () {
541
572
  var _this = this;
@@ -660,6 +691,13 @@ var BruceApi = /** @class */ (function (_super) {
660
691
  });
661
692
  });
662
693
  };
694
+ BruceApi.prototype.PUT = function (url, data, params) {
695
+ return __awaiter(this, void 0, void 0, function () {
696
+ return __generator(this, function (_a) {
697
+ return [2 /*return*/, this.put(this.baseUrl + url, data, params)];
698
+ });
699
+ });
700
+ };
663
701
  BruceApi.prototype.UPLOAD = function (url, blob, params) {
664
702
  return __awaiter(this, void 0, void 0, function () {
665
703
  return __generator(this, function (_a) {
@@ -2282,6 +2320,10 @@ var EntityLod;
2282
2320
  return Api.ECacheKey.Lod + Api.ECacheKey.Id + url;
2283
2321
  }
2284
2322
  EntityLod.GetCacheKey = GetCacheKey;
2323
+ function GetTypeListKey(typeId, group) {
2324
+ return Api.ECacheKey.Lod + Api.ECacheKey.EntityType + typeId + Api.ECacheKey.Id + group;
2325
+ }
2326
+ EntityLod.GetTypeListKey = GetTypeListKey;
2285
2327
  function GetUrl(api, entityId, categoryId, level, strict) {
2286
2328
  if (!entityId) {
2287
2329
  throw ("Entity ID is required.");
@@ -2355,6 +2397,51 @@ var EntityLod;
2355
2397
  });
2356
2398
  }
2357
2399
  EntityLod.GetLods = GetLods;
2400
+ /**
2401
+ * Returns lods for a specified entity type.
2402
+ * @param api
2403
+ * @param typeId
2404
+ * @param group default is "DEFAULT".
2405
+ */
2406
+ function GetTypeLods(api, typeId, group) {
2407
+ return __awaiter(this, void 0, void 0, function () {
2408
+ var cacheData, url, req, prom;
2409
+ var _this = this;
2410
+ return __generator(this, function (_a) {
2411
+ if (!group) {
2412
+ group = "DEFAULT";
2413
+ }
2414
+ cacheData = api.Cache.Get(GetTypeListKey(typeId, group));
2415
+ if (cacheData) {
2416
+ return [2 /*return*/, cacheData];
2417
+ }
2418
+ url = "entityType/" + typeId + "/lods?includeClientFiles=yes" + (group ? "&group=" + group : "");
2419
+ req = api.GET(url, Api.PrepReqParams());
2420
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2421
+ var data, e_2;
2422
+ return __generator(this, function (_a) {
2423
+ switch (_a.label) {
2424
+ case 0:
2425
+ _a.trys.push([0, 2, , 3]);
2426
+ return [4 /*yield*/, req];
2427
+ case 1:
2428
+ data = _a.sent();
2429
+ res(data.Items);
2430
+ return [3 /*break*/, 3];
2431
+ case 2:
2432
+ e_2 = _a.sent();
2433
+ rej(e_2);
2434
+ return [3 /*break*/, 3];
2435
+ case 3: return [2 /*return*/];
2436
+ }
2437
+ });
2438
+ }); });
2439
+ api.Cache.Set(GetTypeListKey(typeId, group), prom, Api.DEFAULT_CACHE_DURATION);
2440
+ return [2 /*return*/, prom];
2441
+ });
2442
+ });
2443
+ }
2444
+ EntityLod.GetTypeLods = GetTypeLods;
2358
2445
  })(EntityLod || (EntityLod = {}));
2359
2446
 
2360
2447
  /**
@@ -4440,18 +4527,33 @@ var ProjectView;
4440
4527
  ProjectView.Delete = Delete;
4441
4528
  function Update(api, data) {
4442
4529
  return __awaiter(this, void 0, void 0, function () {
4530
+ var isNew;
4443
4531
  return __generator(this, function (_a) {
4444
4532
  switch (_a.label) {
4445
4533
  case 0:
4446
- if (!(data === null || data === void 0 ? void 0 : data.ID)) {
4534
+ if (!data) {
4535
+ data = {};
4536
+ }
4537
+ isNew = !data.ID;
4538
+ if (!data.ID) {
4447
4539
  data.ID = ObjectUtils.UId();
4448
4540
  }
4449
- if (!(data === null || data === void 0 ? void 0 : data.Name)) {
4541
+ if (!data.Name) {
4450
4542
  data.Name = data.ID;
4451
4543
  }
4452
- return [4 /*yield*/, api.POST("ui.view", data, Api.PrepReqParams())];
4544
+ if (!data.CreatedByUIVersion) {
4545
+ data.CreatedByUIVersion = "-1";
4546
+ }
4547
+ if (!isNew) return [3 /*break*/, 2];
4548
+ return [4 /*yield*/, api.POST("ui.view/" + data.ID, data, Api.PrepReqParams())];
4453
4549
  case 1:
4454
4550
  data = _a.sent();
4551
+ return [3 /*break*/, 4];
4552
+ case 2: return [4 /*yield*/, api.PUT("ui.view/" + data.ID, data, Api.PrepReqParams())];
4553
+ case 3:
4554
+ data = _a.sent();
4555
+ _a.label = 4;
4556
+ case 4:
4455
4557
  api.Cache.Remove(GetCacheKey(data.ID));
4456
4558
  api.Cache.Remove(GetListCacheKey());
4457
4559
  return [2 /*return*/, data];