bruce-models 0.3.1 → 0.3.3

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.
@@ -2268,6 +2268,10 @@
2268
2268
  return exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.Id + url;
2269
2269
  }
2270
2270
  EntityLod.GetCacheKey = GetCacheKey;
2271
+ function GetTypeListKey(typeId, group) {
2272
+ return exports.Api.ECacheKey.Lod + exports.Api.ECacheKey.EntityType + typeId + exports.Api.ECacheKey.Id + group;
2273
+ }
2274
+ EntityLod.GetTypeListKey = GetTypeListKey;
2271
2275
  function GetUrl(api, entityId, categoryId, level, strict) {
2272
2276
  if (!entityId) {
2273
2277
  throw ("Entity ID is required.");
@@ -2341,6 +2345,51 @@
2341
2345
  });
2342
2346
  }
2343
2347
  EntityLod.GetLods = GetLods;
2348
+ /**
2349
+ * Returns lods for a specified entity type.
2350
+ * @param api
2351
+ * @param typeId
2352
+ * @param group default is "DEFAULT".
2353
+ */
2354
+ function GetTypeLods(api, typeId, group) {
2355
+ return __awaiter(this, void 0, void 0, function () {
2356
+ var cacheData, url, req, prom;
2357
+ var _this = this;
2358
+ return __generator(this, function (_a) {
2359
+ if (!group) {
2360
+ group = "DEFAULT";
2361
+ }
2362
+ cacheData = api.Cache.Get(GetTypeListKey(typeId, group));
2363
+ if (cacheData) {
2364
+ return [2 /*return*/, cacheData];
2365
+ }
2366
+ url = "entityType/" + typeId + "/lods?includeClientFiles=yes" + (group ? "&group=" + group : "");
2367
+ req = api.GET(url, exports.Api.PrepReqParams());
2368
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2369
+ var data, e_2;
2370
+ return __generator(this, function (_a) {
2371
+ switch (_a.label) {
2372
+ case 0:
2373
+ _a.trys.push([0, 2, , 3]);
2374
+ return [4 /*yield*/, req];
2375
+ case 1:
2376
+ data = _a.sent();
2377
+ res(data.Items);
2378
+ return [3 /*break*/, 3];
2379
+ case 2:
2380
+ e_2 = _a.sent();
2381
+ rej(e_2);
2382
+ return [3 /*break*/, 3];
2383
+ case 3: return [2 /*return*/];
2384
+ }
2385
+ });
2386
+ }); });
2387
+ api.Cache.Set(GetTypeListKey(typeId, group), prom, exports.Api.DEFAULT_CACHE_DURATION);
2388
+ return [2 /*return*/, prom];
2389
+ });
2390
+ });
2391
+ }
2392
+ EntityLod.GetTypeLods = GetTypeLods;
2344
2393
  })(exports.EntityLod || (exports.EntityLod = {}));
2345
2394
 
2346
2395
  (function (EntityRelationType) {
@@ -5277,165 +5326,6 @@
5277
5326
  })(AccessToken = User.AccessToken || (User.AccessToken = {}));
5278
5327
  })(exports.User || (exports.User = {}));
5279
5328
 
5280
- (function (EncryptUtils) {
5281
- // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
5282
- function Cyrb53Hash(str, seed) {
5283
- if (seed === void 0) { seed = 0; }
5284
- var h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
5285
- for (var i = 0, ch = void 0; i < str.length; i++) {
5286
- ch = str.charCodeAt(i);
5287
- h1 = Math.imul(h1 ^ ch, 2654435761);
5288
- h2 = Math.imul(h2 ^ ch, 1597334677);
5289
- }
5290
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
5291
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
5292
- return (4294967296 * (2097151 & h2) + (h1 >>> 0));
5293
- }
5294
- EncryptUtils.Cyrb53Hash = Cyrb53Hash;
5295
- })(exports.EncryptUtils || (exports.EncryptUtils = {}));
5296
-
5297
- (function (MathUtils) {
5298
- /**
5299
- * Rounds a number to a given number of decimal places.
5300
- * @param num
5301
- * @param decimals
5302
- * @returns
5303
- */
5304
- function Round(num, decimals) {
5305
- if (decimals === void 0) { decimals = 0; }
5306
- if (decimals <= 0) {
5307
- return Math.round(num);
5308
- }
5309
- var tmp = "1";
5310
- for (var i = 0; i < decimals; i++) {
5311
- tmp += "0";
5312
- }
5313
- var d = parseFloat(tmp);
5314
- return Math.round((num + Number.EPSILON) * d) / d;
5315
- }
5316
- MathUtils.Round = Round;
5317
- /**
5318
- * Returns a random integer between min (inclusive) and max (inclusive).
5319
- * @param min
5320
- * @param max
5321
- * @returns
5322
- */
5323
- function RandInt(min, max) {
5324
- if (min == max) {
5325
- return min;
5326
- }
5327
- else if (min > max) {
5328
- throw ("Min is greater than max.");
5329
- }
5330
- return Math.floor(Math.random() * (max - min + 1)) + min;
5331
- }
5332
- MathUtils.RandInt = RandInt;
5333
- })(exports.MathUtils || (exports.MathUtils = {}));
5334
-
5335
- /**
5336
- * Utility to help with url manipulation.
5337
- */
5338
- (function (UrlUtils) {
5339
- function GetQueryString(doc) {
5340
- var qs = {};
5341
- var p0 = doc.location.href.indexOf("?");
5342
- if (p0 >= 0) {
5343
- var str = doc.location.href.substring(p0 + 1);
5344
- var tokens = str.split("&");
5345
- tokens.forEach(function (token) {
5346
- var p = token.split("=");
5347
- if (p.length == 2) {
5348
- qs[p[0]] = p[1];
5349
- }
5350
- });
5351
- }
5352
- return qs;
5353
- }
5354
- UrlUtils.GetQueryString = GetQueryString;
5355
- /**
5356
- * Helper to get and set url params for a given window.
5357
- */
5358
- var Handler = /** @class */ (function () {
5359
- function Handler(window, allowedKeys) {
5360
- this._allowedKeys = null;
5361
- this._window = window;
5362
- this._allowedKeys = allowedKeys;
5363
- }
5364
- Object.defineProperty(Handler.prototype, "window", {
5365
- get: function () {
5366
- return this._window;
5367
- },
5368
- enumerable: false,
5369
- configurable: true
5370
- });
5371
- Object.defineProperty(Handler.prototype, "document", {
5372
- get: function () {
5373
- var _a;
5374
- return (_a = this.window) === null || _a === void 0 ? void 0 : _a.document;
5375
- },
5376
- enumerable: false,
5377
- configurable: true
5378
- });
5379
- Object.defineProperty(Handler.prototype, "allowedKeys", {
5380
- get: function () {
5381
- return this._allowedKeys;
5382
- },
5383
- enumerable: false,
5384
- configurable: true
5385
- });
5386
- Handler.prototype.UpdateAllowedKeys = function (allowedKeys) {
5387
- this._allowedKeys = allowedKeys;
5388
- var params = this.GetParams();
5389
- this.refresh(params);
5390
- };
5391
- Handler.prototype.UpdateParam = function (key, value) {
5392
- var params = this.GetParams();
5393
- params[key + ""] = value + "";
5394
- this.refresh(params);
5395
- };
5396
- Handler.prototype.RemoveParam = function (key) {
5397
- var params = this.GetParams();
5398
- params[key + ""] = null;
5399
- this.refresh(params);
5400
- };
5401
- Handler.prototype.GetParamKeys = function () {
5402
- var params = GetQueryString(this.document);
5403
- return Object.keys(params);
5404
- };
5405
- Handler.prototype.GetParams = function () {
5406
- return GetQueryString(this.document);
5407
- };
5408
- Handler.prototype.GetParam = function (key) {
5409
- var params = this.GetParams();
5410
- return params[key + ""];
5411
- };
5412
- Handler.prototype.Clear = function () {
5413
- this.refresh({});
5414
- };
5415
- Handler.prototype.refresh = function (data) {
5416
- var params = [];
5417
- var keys = Object.keys(data);
5418
- for (var i = 0; i < keys.length; i++) {
5419
- var key = keys[i];
5420
- if (this._allowedKeys == null || this._allowedKeys.includes(key)) {
5421
- var val = data[key];
5422
- if (!!val || val == 0) {
5423
- params.push(key + "=" + val);
5424
- }
5425
- }
5426
- }
5427
- if (params.length > 0) {
5428
- this.window.history.replaceState({}, null, "?" + params.join("&"));
5429
- }
5430
- else {
5431
- this.window.history.replaceState({}, null, "");
5432
- }
5433
- };
5434
- return Handler;
5435
- }());
5436
- UrlUtils.Handler = Handler;
5437
- })(exports.UrlUtils || (exports.UrlUtils = {}));
5438
-
5439
5329
  var ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
5440
5330
  (function (Account) {
5441
5331
  function GetCacheKey(accountId, appSettingsId) {
@@ -5622,6 +5512,215 @@
5622
5512
  Account.Create = Create;
5623
5513
  })(exports.Account || (exports.Account = {}));
5624
5514
 
5515
+ (function (EncryptUtils) {
5516
+ // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
5517
+ function Cyrb53Hash(str, seed) {
5518
+ if (seed === void 0) { seed = 0; }
5519
+ var h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
5520
+ for (var i = 0, ch = void 0; i < str.length; i++) {
5521
+ ch = str.charCodeAt(i);
5522
+ h1 = Math.imul(h1 ^ ch, 2654435761);
5523
+ h2 = Math.imul(h2 ^ ch, 1597334677);
5524
+ }
5525
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
5526
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
5527
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0));
5528
+ }
5529
+ EncryptUtils.Cyrb53Hash = Cyrb53Hash;
5530
+ })(exports.EncryptUtils || (exports.EncryptUtils = {}));
5531
+
5532
+ (function (MathUtils) {
5533
+ /**
5534
+ * Rounds a number to a given number of decimal places.
5535
+ * @param num
5536
+ * @param decimals
5537
+ * @returns
5538
+ */
5539
+ function Round(num, decimals) {
5540
+ if (decimals === void 0) { decimals = 0; }
5541
+ if (decimals <= 0) {
5542
+ return Math.round(num);
5543
+ }
5544
+ var tmp = "1";
5545
+ for (var i = 0; i < decimals; i++) {
5546
+ tmp += "0";
5547
+ }
5548
+ var d = parseFloat(tmp);
5549
+ return Math.round((num + Number.EPSILON) * d) / d;
5550
+ }
5551
+ MathUtils.Round = Round;
5552
+ /**
5553
+ * Returns a random integer between min (inclusive) and max (inclusive).
5554
+ * @param min
5555
+ * @param max
5556
+ * @returns
5557
+ */
5558
+ function RandInt(min, max) {
5559
+ if (min == max) {
5560
+ return min;
5561
+ }
5562
+ else if (min > max) {
5563
+ throw ("Min is greater than max.");
5564
+ }
5565
+ return Math.floor(Math.random() * (max - min + 1)) + min;
5566
+ }
5567
+ MathUtils.RandInt = RandInt;
5568
+ })(exports.MathUtils || (exports.MathUtils = {}));
5569
+
5570
+ /**
5571
+ * Utility to help with url manipulation.
5572
+ */
5573
+ (function (UrlUtils) {
5574
+ function GetQueryString(doc) {
5575
+ var qs = {};
5576
+ var p0 = doc.location.href.indexOf("?");
5577
+ if (p0 >= 0) {
5578
+ var str = doc.location.href.substring(p0 + 1);
5579
+ var tokens = str.split("&");
5580
+ tokens.forEach(function (token) {
5581
+ var p = token.split("=");
5582
+ if (p.length == 2) {
5583
+ qs[p[0]] = p[1];
5584
+ }
5585
+ });
5586
+ }
5587
+ return qs;
5588
+ }
5589
+ UrlUtils.GetQueryString = GetQueryString;
5590
+ /**
5591
+ * Helper to get and set url params for a given window.
5592
+ */
5593
+ var Handler = /** @class */ (function () {
5594
+ function Handler(window, allowedKeys) {
5595
+ this._allowedKeys = null;
5596
+ this._window = window;
5597
+ this._allowedKeys = allowedKeys;
5598
+ }
5599
+ Object.defineProperty(Handler.prototype, "window", {
5600
+ get: function () {
5601
+ return this._window;
5602
+ },
5603
+ enumerable: false,
5604
+ configurable: true
5605
+ });
5606
+ Object.defineProperty(Handler.prototype, "document", {
5607
+ get: function () {
5608
+ var _a;
5609
+ return (_a = this.window) === null || _a === void 0 ? void 0 : _a.document;
5610
+ },
5611
+ enumerable: false,
5612
+ configurable: true
5613
+ });
5614
+ Object.defineProperty(Handler.prototype, "allowedKeys", {
5615
+ get: function () {
5616
+ return this._allowedKeys;
5617
+ },
5618
+ enumerable: false,
5619
+ configurable: true
5620
+ });
5621
+ Handler.prototype.UpdateAllowedKeys = function (allowedKeys) {
5622
+ this._allowedKeys = allowedKeys;
5623
+ var params = this.GetParams();
5624
+ this.refresh(params);
5625
+ };
5626
+ Handler.prototype.UpdateParam = function (key, value) {
5627
+ var params = this.GetParams();
5628
+ params[key + ""] = value + "";
5629
+ this.refresh(params);
5630
+ };
5631
+ Handler.prototype.RemoveParam = function (key) {
5632
+ var params = this.GetParams();
5633
+ params[key + ""] = null;
5634
+ this.refresh(params);
5635
+ };
5636
+ Handler.prototype.GetParamKeys = function () {
5637
+ var params = GetQueryString(this.document);
5638
+ return Object.keys(params);
5639
+ };
5640
+ Handler.prototype.GetParams = function () {
5641
+ return GetQueryString(this.document);
5642
+ };
5643
+ Handler.prototype.GetParam = function (key) {
5644
+ var params = this.GetParams();
5645
+ return params[key + ""];
5646
+ };
5647
+ Handler.prototype.Clear = function () {
5648
+ this.refresh({});
5649
+ };
5650
+ Handler.prototype.refresh = function (data) {
5651
+ var params = [];
5652
+ var keys = Object.keys(data);
5653
+ for (var i = 0; i < keys.length; i++) {
5654
+ var key = keys[i];
5655
+ if (this._allowedKeys == null || this._allowedKeys.includes(key)) {
5656
+ var val = data[key];
5657
+ if (!!val || val == 0) {
5658
+ params.push(key + "=" + val);
5659
+ }
5660
+ }
5661
+ }
5662
+ if (params.length > 0) {
5663
+ this.window.history.replaceState({}, null, "?" + params.join("&"));
5664
+ }
5665
+ else {
5666
+ this.window.history.replaceState({}, null, "");
5667
+ }
5668
+ };
5669
+ return Handler;
5670
+ }());
5671
+ UrlUtils.Handler = Handler;
5672
+ })(exports.UrlUtils || (exports.UrlUtils = {}));
5673
+
5674
+ (function (DataLab) {
5675
+ var EReqKey;
5676
+ (function (EReqKey) {
5677
+ EReqKey["Primary"] = "PrimarySelection";
5678
+ EReqKey["Secondary"] = "SecondarySelection";
5679
+ })(EReqKey = DataLab.EReqKey || (DataLab.EReqKey = {}));
5680
+ var Entity;
5681
+ (function (Entity) {
5682
+ function GetList(api, query, key, skip, load) {
5683
+ return __awaiter(this, void 0, void 0, function () {
5684
+ var req, prom;
5685
+ var _this = this;
5686
+ return __generator(this, function (_a) {
5687
+ if (!key) {
5688
+ key = EReqKey.Primary;
5689
+ }
5690
+ if (!skip) {
5691
+ skip = 0;
5692
+ }
5693
+ if (!load) {
5694
+ load = 50;
5695
+ }
5696
+ req = api.POST("entities/datalab/getMatchingEntities/" + key + "?skip=" + skip + "&load=" + load, query, exports.Api.PrepReqParams());
5697
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5698
+ var data, e_1;
5699
+ return __generator(this, function (_a) {
5700
+ switch (_a.label) {
5701
+ case 0:
5702
+ _a.trys.push([0, 2, , 3]);
5703
+ return [4 /*yield*/, req];
5704
+ case 1:
5705
+ data = _a.sent();
5706
+ res(data.Items);
5707
+ return [3 /*break*/, 3];
5708
+ case 2:
5709
+ e_1 = _a.sent();
5710
+ rej(e_1);
5711
+ return [3 /*break*/, 3];
5712
+ case 3: return [2 /*return*/];
5713
+ }
5714
+ });
5715
+ }); });
5716
+ return [2 /*return*/, prom];
5717
+ });
5718
+ });
5719
+ }
5720
+ Entity.GetList = GetList;
5721
+ })(Entity = DataLab.Entity || (DataLab.Entity = {}));
5722
+ })(exports.DataLab || (exports.DataLab = {}));
5723
+
5625
5724
  exports.AbstractApi = AbstractApi;
5626
5725
  exports.BruceApi = BruceApi;
5627
5726
  exports.CamApi = CamApi;