bruce-models 0.0.1 → 0.0.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.
@@ -0,0 +1,4784 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
+ this file except in compliance with the License. You may obtain a copy of the
5
+ License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10
+ MERCHANTABLITY OR NON-INFRINGEMENT.
11
+
12
+ See the Apache Version 2.0 License for specific language governing permissions
13
+ and limitations under the License.
14
+ ***************************************************************************** */
15
+ /* global Reflect, Promise */
16
+
17
+ var extendStatics = function(d, b) {
18
+ extendStatics = Object.setPrototypeOf ||
19
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
20
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
21
+ return extendStatics(d, b);
22
+ };
23
+
24
+ function __extends(d, b) {
25
+ extendStatics(d, b);
26
+ function __() { this.constructor = d; }
27
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28
+ }
29
+
30
+ var __assign = function() {
31
+ __assign = Object.assign || function __assign(t) {
32
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
33
+ s = arguments[i];
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
35
+ }
36
+ return t;
37
+ };
38
+ return __assign.apply(this, arguments);
39
+ };
40
+
41
+ function __awaiter(thisArg, _arguments, P, generator) {
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ }
49
+
50
+ function __generator(thisArg, body) {
51
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
52
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
53
+ function verb(n) { return function (v) { return step([n, v]); }; }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (_) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0: case 1: t = op; break;
61
+ case 4: _.label++; return { value: op[1], done: false };
62
+ case 5: _.label++; y = op[1]; op = [0]; continue;
63
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
64
+ default:
65
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
66
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
67
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
68
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
69
+ if (t[2]) _.ops.pop();
70
+ _.trys.pop(); continue;
71
+ }
72
+ op = body.call(thisArg, _);
73
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
74
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
75
+ }
76
+ }
77
+
78
+ var Api;
79
+ (function (Api) {
80
+ var ECacheKey;
81
+ (function (ECacheKey) {
82
+ ECacheKey["Id"] = ":";
83
+ ECacheKey["Entity"] = "entity";
84
+ ECacheKey["EntityType"] = "entitytype";
85
+ ECacheKey["ProjectView"] = "projectview";
86
+ ECacheKey["ProjectViewBookmark"] = "pvbookmark";
87
+ ECacheKey["Tileset"] = "tileset";
88
+ ECacheKey["ClientFile"] = "clientfile";
89
+ ECacheKey["Session"] = "session";
90
+ ECacheKey["PendingAction"] = "pendingaction";
91
+ ECacheKey["EntitySource"] = "entitysource";
92
+ ECacheKey["ProgramKey"] = "programkey";
93
+ ECacheKey["Ucs"] = "ucs";
94
+ ECacheKey["Tag"] = "tag";
95
+ ECacheKey["Attachment"] = "attachment";
96
+ ECacheKey["Comment"] = "comment";
97
+ ECacheKey["Link"] = "link";
98
+ ECacheKey["AnnDocument"] = "anndocument";
99
+ ECacheKey["AttachmentType"] = "attachmenttype";
100
+ ECacheKey["Relation"] = "relation";
101
+ ECacheKey["RelationType"] = "relationtype";
102
+ ECacheKey["Lod"] = "lod";
103
+ ECacheKey["Style"] = "style";
104
+ ECacheKey["PublishTileset"] = "publishtileset";
105
+ ECacheKey["User"] = "user";
106
+ ECacheKey["AccessToken"] = "accesstoken";
107
+ ECacheKey["UserGroup"] = "usergroup";
108
+ ECacheKey["Account"] = "account";
109
+ })(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
110
+ Api.DEFAULT_CACHE_DURATION = 60 * 5; // 5 minutes.
111
+ Api.TEMPLATE_ACCOUNT_ID = "template";
112
+ Api.ACCESS_TOKEN_HEADER = "X-Access-Token";
113
+ function Encode(str) {
114
+ return encodeURIComponent(str.replace(/\+/g, "%2B").replace(/\./g, "%2E"));
115
+ }
116
+ Api.Encode = Encode;
117
+ var ESortOrder;
118
+ (function (ESortOrder) {
119
+ ESortOrder[ESortOrder["None"] = 0] = "None";
120
+ ESortOrder[ESortOrder["Asc"] = 1] = "Asc";
121
+ ESortOrder[ESortOrder["Desc"] = -1] = "Desc";
122
+ })(ESortOrder = Api.ESortOrder || (Api.ESortOrder = {}));
123
+ var EEncoding;
124
+ (function (EEncoding) {
125
+ EEncoding["UTF8"] = "UTF-8";
126
+ EEncoding["UTF16"] = "UTF-16BE";
127
+ })(EEncoding = Api.EEncoding || (Api.EEncoding = {}));
128
+ var EEnv;
129
+ (function (EEnv) {
130
+ EEnv["DEV"] = "DEV";
131
+ EEnv["STG"] = "STG";
132
+ EEnv["UAT"] = "UAT";
133
+ EEnv["PROD"] = "PROD";
134
+ })(EEnv = Api.EEnv || (Api.EEnv = {}));
135
+ function PrepReqParams() {
136
+ return { response: { encoding: Api.EEncoding.UTF16 } };
137
+ }
138
+ Api.PrepReqParams = PrepReqParams;
139
+ })(Api || (Api = {}));
140
+
141
+ var AnnDocument;
142
+ (function (AnnDocument) {
143
+ function GetCacheKey(id) {
144
+ return "" + Api.ECacheKey.AnnDocument + Api.ECacheKey.Id + id;
145
+ }
146
+ AnnDocument.GetCacheKey = GetCacheKey;
147
+ function GetListCacheKey(type) {
148
+ return Api.ECacheKey.AnnDocument + type;
149
+ }
150
+ AnnDocument.GetListCacheKey = GetListCacheKey;
151
+ var EType;
152
+ (function (EType) {
153
+ EType["SVG"] = "SVG";
154
+ })(EType = AnnDocument.EType || (AnnDocument.EType = {}));
155
+ function Get(api, docId) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var key, cacheData, req;
158
+ return __generator(this, function (_a) {
159
+ if (!docId) {
160
+ throw ("Doc ID is required.");
161
+ }
162
+ key = GetCacheKey(docId);
163
+ cacheData = api.Cache.Get(key);
164
+ if (cacheData) {
165
+ return [2 /*return*/, cacheData];
166
+ }
167
+ req = api.GET("documentView/" + docId, Api.PrepReqParams());
168
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
169
+ return [2 /*return*/, req];
170
+ });
171
+ });
172
+ }
173
+ AnnDocument.Get = Get;
174
+ function GetList(api, type) {
175
+ return __awaiter(this, void 0, void 0, function () {
176
+ var cacheData, req;
177
+ var _this = this;
178
+ return __generator(this, function (_a) {
179
+ if (!type) {
180
+ type = "";
181
+ }
182
+ cacheData = api.Cache.Get(GetListCacheKey(type));
183
+ if (cacheData) {
184
+ return [2 /*return*/, cacheData];
185
+ }
186
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
187
+ var url, data, e_1;
188
+ return __generator(this, function (_a) {
189
+ switch (_a.label) {
190
+ case 0:
191
+ _a.trys.push([0, 2, , 3]);
192
+ url = "documentViews" + (type ? "?type=" + type : "");
193
+ return [4 /*yield*/, api.GET(url, Api.PrepReqParams())];
194
+ case 1:
195
+ data = _a.sent();
196
+ res(data.Items);
197
+ return [3 /*break*/, 3];
198
+ case 2:
199
+ e_1 = _a.sent();
200
+ rej(e_1);
201
+ return [3 /*break*/, 3];
202
+ case 3: return [2 /*return*/];
203
+ }
204
+ });
205
+ }); });
206
+ api.Cache.Set(GetListCacheKey(type), req);
207
+ return [2 /*return*/, req];
208
+ });
209
+ });
210
+ }
211
+ AnnDocument.GetList = GetList;
212
+ })(AnnDocument || (AnnDocument = {}));
213
+
214
+ var CacheItem = /** @class */ (function () {
215
+ function CacheItem(id, data, duration) {
216
+ this.Id = id;
217
+ this.Data = data;
218
+ this.Duration = duration;
219
+ this._created = duration > -1 ? new Date() : null;
220
+ }
221
+ CacheItem.prototype.IsExpired = function () {
222
+ if (this._created == null) {
223
+ return false;
224
+ }
225
+ return (new Date().getTime() - this._created.getTime()) / 1000 > this.Duration;
226
+ };
227
+ return CacheItem;
228
+ }());
229
+ var CacheControl = /** @class */ (function () {
230
+ function CacheControl() {
231
+ this.data = {};
232
+ }
233
+ CacheControl.prototype.Set = function (id, data, duration) {
234
+ if (duration === void 0) { duration = -1; }
235
+ this.data[id + ""] = new CacheItem(id + "", data, duration);
236
+ };
237
+ CacheControl.prototype.Get = function (id) {
238
+ var item = this.data[id + ""];
239
+ if (item == null) {
240
+ return null;
241
+ }
242
+ if (item.IsExpired()) {
243
+ delete this.data[id + ""];
244
+ return null;
245
+ }
246
+ return item.Data;
247
+ };
248
+ CacheControl.prototype.Clear = function () {
249
+ this.data = {};
250
+ };
251
+ CacheControl.prototype.Remove = function (id) {
252
+ delete this.data[id + ""];
253
+ };
254
+ CacheControl.prototype.RemoveByStartsWith = function (text) {
255
+ for (var key in this.data) {
256
+ if (key.startsWith(text)) {
257
+ delete this.data[key];
258
+ }
259
+ }
260
+ };
261
+ CacheControl.prototype.RemoveByContains = function (text) {
262
+ for (var key in this.data) {
263
+ if (key.includes(text)) {
264
+ delete this.data[key];
265
+ }
266
+ }
267
+ };
268
+ CacheControl.prototype.GetKeys = function () {
269
+ return Object.keys(this.data);
270
+ };
271
+ CacheControl.prototype.GetValues = function () {
272
+ var values = [];
273
+ for (var key in this.data) {
274
+ var data = this.Get(key);
275
+ if (data != null) {
276
+ values.push(data);
277
+ }
278
+ }
279
+ return values;
280
+ };
281
+ return CacheControl;
282
+ }());
283
+
284
+ function parseResult(data, encoding) {
285
+ return __awaiter(this, void 0, void 0, function () {
286
+ var buffer, error;
287
+ return __generator(this, function (_a) {
288
+ switch (_a.label) {
289
+ case 0:
290
+ if (!(data.status == 200)) return [3 /*break*/, 4];
291
+ if (!encoding) return [3 /*break*/, 2];
292
+ return [4 /*yield*/, data.arrayBuffer()];
293
+ case 1:
294
+ buffer = _a.sent();
295
+ return [2 /*return*/, JSON.parse(new TextDecoder(encoding).decode(buffer))];
296
+ case 2: return [2 /*return*/, data.json()];
297
+ case 3: return [3 /*break*/, 6];
298
+ case 4: return [4 /*yield*/, data.json()];
299
+ case 5:
300
+ error = _a.sent();
301
+ throw (error);
302
+ case 6: return [2 /*return*/];
303
+ }
304
+ });
305
+ });
306
+ }
307
+ var AbstractApi = /** @class */ (function () {
308
+ function AbstractApi(ssidHeader) {
309
+ this.ssid = "";
310
+ this.Cache = new CacheControl();
311
+ this.ssidHeader = ssidHeader;
312
+ }
313
+ AbstractApi.prototype.GetSessionId = function () {
314
+ return this.ssid;
315
+ };
316
+ AbstractApi.prototype.SetSessionId = function (value) {
317
+ this.ssid = value;
318
+ };
319
+ AbstractApi.prototype.GetSessionHeader = function () {
320
+ return this.ssidHeader;
321
+ };
322
+ AbstractApi.prototype.SetSessionHeader = function (value) {
323
+ this.ssidHeader = value;
324
+ };
325
+ AbstractApi.prototype.get = function (url, params) {
326
+ var _a;
327
+ return __awaiter(this, void 0, void 0, function () {
328
+ var res;
329
+ var _b;
330
+ return __generator(this, function (_c) {
331
+ switch (_c.label) {
332
+ case 0:
333
+ if (!params) {
334
+ params = {};
335
+ }
336
+ params.headers = params.headers || {};
337
+ params.headers = __assign((_b = { "Content-Type": "application/json;" }, _b[this.ssidHeader] = this.ssid, _b), params.headers);
338
+ return [4 /*yield*/, fetch(url, {
339
+ headers: params.headers
340
+ })];
341
+ case 1:
342
+ res = _c.sent();
343
+ return [2 /*return*/, parseResult(res, (_a = params.response) === null || _a === void 0 ? void 0 : _a.encoding)];
344
+ }
345
+ });
346
+ });
347
+ };
348
+ AbstractApi.prototype.delete = function (url, params) {
349
+ var _a;
350
+ return __awaiter(this, void 0, void 0, function () {
351
+ var res;
352
+ var _b;
353
+ return __generator(this, function (_c) {
354
+ switch (_c.label) {
355
+ case 0:
356
+ if (!params) {
357
+ params = {};
358
+ }
359
+ params.headers = params.headers || {};
360
+ params.headers = __assign((_b = { "Content-Type": "application/json;" }, _b[this.ssidHeader] = this.ssid, _b), params.headers);
361
+ return [4 /*yield*/, fetch(url, {
362
+ headers: params.headers,
363
+ method: "DELETE"
364
+ })];
365
+ case 1:
366
+ res = _c.sent();
367
+ return [2 /*return*/, parseResult(res, (_a = params.response) === null || _a === void 0 ? void 0 : _a.encoding)];
368
+ }
369
+ });
370
+ });
371
+ };
372
+ AbstractApi.prototype.post = function (url, data, params) {
373
+ var _a;
374
+ return __awaiter(this, void 0, void 0, function () {
375
+ var res;
376
+ var _b;
377
+ return __generator(this, function (_c) {
378
+ switch (_c.label) {
379
+ case 0:
380
+ if (!params) {
381
+ params = {};
382
+ }
383
+ params.headers = params.headers || {};
384
+ params.headers = __assign((_b = { "Content-Type": "application/json;" }, _b[this.ssidHeader] = this.ssid, _b), params.headers);
385
+ if (!data) {
386
+ data = {};
387
+ }
388
+ if (typeof data != "string") {
389
+ data = JSON.stringify(data);
390
+ }
391
+ return [4 /*yield*/, fetch(url, {
392
+ headers: params.headers,
393
+ method: "POST",
394
+ body: data
395
+ })];
396
+ case 1:
397
+ res = _c.sent();
398
+ return [2 /*return*/, parseResult(res, (_a = params.response) === null || _a === void 0 ? void 0 : _a.encoding)];
399
+ }
400
+ });
401
+ });
402
+ };
403
+ AbstractApi.prototype.upload = function (url, blob, params) {
404
+ return __awaiter(this, void 0, void 0, function () {
405
+ var _this = this;
406
+ return __generator(this, function (_a) {
407
+ return [2 /*return*/, new Promise(function (res, rej) {
408
+ try {
409
+ var xhr_1 = new XMLHttpRequest();
410
+ var headers = params === null || params === void 0 ? void 0 : params.headers;
411
+ if (headers) {
412
+ var headerKeys = Object.keys(headers);
413
+ for (var i = 0; i < headerKeys.length; i++) {
414
+ var key = headerKeys[i];
415
+ var value = headers[key];
416
+ xhr_1.setRequestHeader(key, value);
417
+ }
418
+ }
419
+ if (params === null || params === void 0 ? void 0 : params.onProgress) {
420
+ if (xhr_1.upload) {
421
+ xhr_1.upload.onprogress = params === null || params === void 0 ? void 0 : params.onProgress;
422
+ }
423
+ else {
424
+ xhr_1.addEventListener("progress", params === null || params === void 0 ? void 0 : params.onProgress);
425
+ }
426
+ }
427
+ xhr_1.onreadystatechange = function (e) {
428
+ if (xhr_1.readyState == 4) {
429
+ if (xhr_1.status >= 400) {
430
+ rej(e);
431
+ }
432
+ else {
433
+ try {
434
+ res(JSON.parse(xhr_1.responseText));
435
+ }
436
+ catch (e) {
437
+ console.error(e, xhr_1.responseText);
438
+ res(xhr_1.responseText);
439
+ }
440
+ }
441
+ }
442
+ };
443
+ xhr_1.open("POST", url, true);
444
+ if (_this.ssid) {
445
+ xhr_1.setRequestHeader(_this.ssidHeader, _this.ssid);
446
+ }
447
+ var formData = new FormData();
448
+ formData.append("file", blob);
449
+ xhr_1.send(formData);
450
+ }
451
+ catch (e) {
452
+ rej(e);
453
+ }
454
+ })];
455
+ });
456
+ });
457
+ };
458
+ return AbstractApi;
459
+ }());
460
+
461
+ var BruceApi = /** @class */ (function (_super) {
462
+ __extends(BruceApi, _super);
463
+ function BruceApi(accountId, env) {
464
+ var _this = _super.call(this, "x-sessionid") || this;
465
+ _this.baseUrl = "";
466
+ _this.accountId = accountId;
467
+ _this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
468
+ _this.setBaseUrl();
469
+ return _this;
470
+ }
471
+ BruceApi.prototype.setBaseUrl = function () {
472
+ var prefix = "https://" + this.accountId + ".api.nextspace";
473
+ var url;
474
+ var env = this.env.toUpperCase();
475
+ switch (env) {
476
+ case Api.EEnv.DEV:
477
+ url = prefix + "-dev.net/";
478
+ break;
479
+ case Api.EEnv.STG:
480
+ url = prefix + "-stg.net/";
481
+ break;
482
+ case Api.EEnv.UAT:
483
+ url = prefix + "-uat.net/";
484
+ break;
485
+ case Api.EEnv.PROD:
486
+ url = prefix + ".host/";
487
+ break;
488
+ default:
489
+ throw ("Specified Environment is not valid. SuppliedEnv=" + env);
490
+ }
491
+ this.baseUrl = url;
492
+ };
493
+ BruceApi.prototype.GetBaseUrl = function () {
494
+ return this.baseUrl;
495
+ };
496
+ BruceApi.prototype.GET = function (url, params) {
497
+ return __awaiter(this, void 0, void 0, function () {
498
+ return __generator(this, function (_a) {
499
+ return [2 /*return*/, this.get(this.baseUrl + url, params)];
500
+ });
501
+ });
502
+ };
503
+ BruceApi.prototype.DELETE = function (url, params) {
504
+ return __awaiter(this, void 0, void 0, function () {
505
+ return __generator(this, function (_a) {
506
+ return [2 /*return*/, this.delete(this.baseUrl + url, params)];
507
+ });
508
+ });
509
+ };
510
+ BruceApi.prototype.POST = function (url, data, params) {
511
+ return __awaiter(this, void 0, void 0, function () {
512
+ return __generator(this, function (_a) {
513
+ return [2 /*return*/, this.post(this.baseUrl + url, data, params)];
514
+ });
515
+ });
516
+ };
517
+ BruceApi.prototype.UPLOAD = function (url, blob, params) {
518
+ return __awaiter(this, void 0, void 0, function () {
519
+ return __generator(this, function (_a) {
520
+ return [2 /*return*/, this.upload(this.baseUrl + url, blob, params)];
521
+ });
522
+ });
523
+ };
524
+ return BruceApi;
525
+ }(AbstractApi));
526
+
527
+ var CamApi = /** @class */ (function (_super) {
528
+ __extends(CamApi, _super);
529
+ function CamApi(env) {
530
+ var _this = _super.call(this, "SSID") || this;
531
+ _this.baseUrl = "";
532
+ _this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
533
+ _this.setBaseUrl();
534
+ return _this;
535
+ }
536
+ CamApi.prototype.setBaseUrl = function () {
537
+ var prefix = "https://cam.nextspace";
538
+ var url;
539
+ var env = this.env.toUpperCase();
540
+ switch (env) {
541
+ case Api.EEnv.DEV:
542
+ url = prefix + "-dev.net/";
543
+ break;
544
+ case Api.EEnv.STG:
545
+ url = prefix + "-stg.net/";
546
+ break;
547
+ case Api.EEnv.UAT:
548
+ url = prefix + "-uat.net/";
549
+ break;
550
+ case Api.EEnv.PROD:
551
+ url = prefix + ".host/";
552
+ break;
553
+ default:
554
+ throw ("Specified Environment is not valid. SuppliedEnv=" + env);
555
+ }
556
+ this.baseUrl = url;
557
+ };
558
+ CamApi.prototype.GetBaseUrl = function () {
559
+ return this.baseUrl;
560
+ };
561
+ CamApi.prototype.GET = function (url, params) {
562
+ return __awaiter(this, void 0, void 0, function () {
563
+ return __generator(this, function (_a) {
564
+ return [2 /*return*/, this.get(this.baseUrl + url, params)];
565
+ });
566
+ });
567
+ };
568
+ CamApi.prototype.DELETE = function (url, params) {
569
+ return __awaiter(this, void 0, void 0, function () {
570
+ return __generator(this, function (_a) {
571
+ return [2 /*return*/, this.delete(this.baseUrl + url, params)];
572
+ });
573
+ });
574
+ };
575
+ CamApi.prototype.POST = function (url, data, params) {
576
+ return __awaiter(this, void 0, void 0, function () {
577
+ return __generator(this, function (_a) {
578
+ return [2 /*return*/, this.post(this.baseUrl + url, data, params)];
579
+ });
580
+ });
581
+ };
582
+ CamApi.prototype.UPLOAD = function (url, blob, params) {
583
+ return __awaiter(this, void 0, void 0, function () {
584
+ return __generator(this, function (_a) {
585
+ return [2 /*return*/, this.upload(this.baseUrl + url, blob, params)];
586
+ });
587
+ });
588
+ };
589
+ return CamApi;
590
+ }(AbstractApi));
591
+
592
+ var IdmApi = /** @class */ (function (_super) {
593
+ __extends(IdmApi, _super);
594
+ function IdmApi(env) {
595
+ var _this = _super.call(this, "SSID") || this;
596
+ _this.baseUrl = "";
597
+ _this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
598
+ _this.setBaseUrl();
599
+ return _this;
600
+ }
601
+ IdmApi.prototype.setBaseUrl = function () {
602
+ var prefix = "https://idm.nextspace";
603
+ var url;
604
+ var env = this.env.toUpperCase();
605
+ switch (env) {
606
+ case Api.EEnv.DEV:
607
+ url = prefix + "-dev.net/";
608
+ break;
609
+ case Api.EEnv.STG:
610
+ url = prefix + "-stg.net/";
611
+ break;
612
+ case Api.EEnv.UAT:
613
+ url = prefix + "-uat.net/";
614
+ break;
615
+ case Api.EEnv.PROD:
616
+ url = prefix + ".host/";
617
+ break;
618
+ default:
619
+ throw ("Specified Environment is not valid. SuppliedEnv1=" + env);
620
+ }
621
+ this.baseUrl = url;
622
+ };
623
+ IdmApi.prototype.GetBaseUrl = function () {
624
+ return this.baseUrl;
625
+ };
626
+ IdmApi.prototype.GET = function (url, params) {
627
+ return __awaiter(this, void 0, void 0, function () {
628
+ return __generator(this, function (_a) {
629
+ return [2 /*return*/, this.get(this.baseUrl + url, params)];
630
+ });
631
+ });
632
+ };
633
+ IdmApi.prototype.DELETE = function (url, params) {
634
+ return __awaiter(this, void 0, void 0, function () {
635
+ return __generator(this, function (_a) {
636
+ return [2 /*return*/, this.delete(this.baseUrl + url, params)];
637
+ });
638
+ });
639
+ };
640
+ IdmApi.prototype.POST = function (url, data, params) {
641
+ return __awaiter(this, void 0, void 0, function () {
642
+ return __generator(this, function (_a) {
643
+ return [2 /*return*/, this.post(this.baseUrl + url, data, params)];
644
+ });
645
+ });
646
+ };
647
+ IdmApi.prototype.UPLOAD = function (url, blob, params) {
648
+ return __awaiter(this, void 0, void 0, function () {
649
+ return __generator(this, function (_a) {
650
+ return [2 /*return*/, this.upload(this.baseUrl + url, blob, params)];
651
+ });
652
+ });
653
+ };
654
+ return IdmApi;
655
+ }(AbstractApi));
656
+
657
+ var Color;
658
+ (function (Color) {
659
+ var EBlendMode;
660
+ (function (EBlendMode) {
661
+ EBlendMode[EBlendMode["HIGHLIGHT"] = 0] = "HIGHLIGHT";
662
+ EBlendMode[EBlendMode["REPLACE"] = 1] = "REPLACE";
663
+ EBlendMode[EBlendMode["MIX"] = 2] = "MIX";
664
+ })(EBlendMode = Color.EBlendMode || (Color.EBlendMode = {}));
665
+ function RandomColor() {
666
+ // https://stackoverflow.com/a/7352887
667
+ var brightness = 4;
668
+ var rgb = [Math.random() * 256, Math.random() * 256, Math.random() * 256];
669
+ var mix = [brightness * 51, brightness * 51, brightness * 51];
670
+ var mixedrgb = [rgb[0] + mix[0], rgb[1] + mix[1], rgb[2] + mix[2]].map(function (x) {
671
+ return Math.round(x / 2.0);
672
+ });
673
+ var str = "rgba(" + mixedrgb.join(",") + ",0.9" + ")";
674
+ return ColorFromStr(str);
675
+ }
676
+ Color.RandomColor = RandomColor;
677
+ function ColorFromStr(str) {
678
+ var r, g, b, a;
679
+ var rgba = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([^\)]+)\s*)?\)$/.exec(str);
680
+ if (rgba) {
681
+ r = parseInt(rgba[1]);
682
+ g = parseInt(rgba[2]);
683
+ b = parseInt(rgba[3]);
684
+ a = rgba[4] != null ? parseFloat(rgba[4]) : 1;
685
+ return {
686
+ red: r,
687
+ green: g,
688
+ blue: b,
689
+ alpha: a
690
+ };
691
+ }
692
+ if (str.charAt(0) == "#") {
693
+ str = str.substring(1);
694
+ }
695
+ if (str.length == 6) {
696
+ // rgb.
697
+ var parsed = /^(.{2})(.{2})(.{2})/.exec(str);
698
+ if (!parsed) {
699
+ return null;
700
+ }
701
+ r = parseInt(parsed[1], 16);
702
+ g = parseInt(parsed[2], 16);
703
+ b = parseInt(parsed[3], 16);
704
+ a = 1;
705
+ }
706
+ else if (str.length == 8) {
707
+ // rgba.
708
+ var parsed = /^(.{2})(.{2})(.{2})(.{2})/.exec(str);
709
+ if (!parsed) {
710
+ return null;
711
+ }
712
+ r = parseInt(parsed[1], 16);
713
+ g = parseInt(parsed[2], 16);
714
+ b = parseInt(parsed[3], 16);
715
+ a = parseInt(parsed[4], 16);
716
+ if (a != 0) {
717
+ a = a / 255;
718
+ }
719
+ }
720
+ else {
721
+ return null;
722
+ }
723
+ if (a == null) {
724
+ a = 1;
725
+ }
726
+ return {
727
+ red: r,
728
+ blue: b,
729
+ green: g,
730
+ alpha: a
731
+ };
732
+ }
733
+ Color.ColorFromStr = ColorFromStr;
734
+ })(Color || (Color = {}));
735
+
736
+ var ObjectUtils;
737
+ (function (ObjectUtils) {
738
+ function UId() {
739
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
740
+ var r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
741
+ return v.toString(16);
742
+ });
743
+ }
744
+ ObjectUtils.UId = UId;
745
+ })(ObjectUtils || (ObjectUtils = {}));
746
+
747
+ var Entity;
748
+ (function (Entity) {
749
+ function GetCacheKey(entityId) {
750
+ return "" + Api.ECacheKey.Entity + Api.ECacheKey.Id + entityId;
751
+ }
752
+ Entity.GetCacheKey = GetCacheKey;
753
+ function Get(api, entityId) {
754
+ return __awaiter(this, void 0, void 0, function () {
755
+ var key, cacheData, req;
756
+ return __generator(this, function (_a) {
757
+ if (!entityId) {
758
+ throw ("Entity ID is required.");
759
+ }
760
+ key = GetCacheKey(entityId);
761
+ cacheData = api.Cache.Get(key);
762
+ if (cacheData) {
763
+ return [2 /*return*/, cacheData];
764
+ }
765
+ req = api.GET("entity/" + entityId, Api.PrepReqParams());
766
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
767
+ return [2 /*return*/, req];
768
+ });
769
+ });
770
+ }
771
+ Entity.Get = Get;
772
+ function GetListByIds(api, entityIds) {
773
+ return __awaiter(this, void 0, void 0, function () {
774
+ var reqs, reqIds, i, entityId, key, cacheData, reqData, req, _loop_1, i;
775
+ var _this = this;
776
+ return __generator(this, function (_a) {
777
+ switch (_a.label) {
778
+ case 0:
779
+ if (!entityIds.length) {
780
+ throw ("Entity IDs are required.");
781
+ }
782
+ reqs = [];
783
+ reqIds = [];
784
+ for (i = 0; i < entityIds.length; i++) {
785
+ entityId = entityIds[i];
786
+ key = GetCacheKey(entityId);
787
+ cacheData = api.Cache.Get(key);
788
+ if (cacheData) {
789
+ reqs.push(cacheData);
790
+ }
791
+ else {
792
+ reqIds.push(entityId);
793
+ }
794
+ }
795
+ reqData = {
796
+ Filter: {
797
+ ID: {
798
+ in: reqIds
799
+ }
800
+ },
801
+ PageSize: reqIds.length
802
+ };
803
+ req = api.POST("entities", reqData, Api.PrepReqParams());
804
+ _loop_1 = function (i) {
805
+ var entityId = reqIds[i];
806
+ var key = GetCacheKey(entityId);
807
+ var prom = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
808
+ var data, item, e_1;
809
+ return __generator(this, function (_a) {
810
+ switch (_a.label) {
811
+ case 0:
812
+ _a.trys.push([0, 2, , 3]);
813
+ return [4 /*yield*/, req];
814
+ case 1:
815
+ data = _a.sent();
816
+ item = data.Items.find(function (x) { return x.Bruce.ID == entityId; });
817
+ res(item);
818
+ return [3 /*break*/, 3];
819
+ case 2:
820
+ e_1 = _a.sent();
821
+ return [3 /*break*/, 3];
822
+ case 3:
823
+ res(null);
824
+ return [2 /*return*/];
825
+ }
826
+ });
827
+ }); });
828
+ api.Cache.Set(key, prom, Api.DEFAULT_CACHE_DURATION);
829
+ reqs.push(prom);
830
+ };
831
+ for (i = 0; i < reqIds.length; i++) {
832
+ _loop_1(i);
833
+ }
834
+ return [4 /*yield*/, Promise.all(reqs)];
835
+ case 1: return [2 /*return*/, (_a.sent()).filter(function (x) { return !!x; })];
836
+ }
837
+ });
838
+ });
839
+ }
840
+ Entity.GetListByIds = GetListByIds;
841
+ function Delete(api, entityId) {
842
+ return __awaiter(this, void 0, void 0, function () {
843
+ return __generator(this, function (_a) {
844
+ switch (_a.label) {
845
+ case 0:
846
+ if (!entityId) {
847
+ throw ("Entity ID is required.");
848
+ }
849
+ return [4 /*yield*/, api.DELETE("entity/" + entityId, Api.PrepReqParams())];
850
+ case 1:
851
+ _a.sent();
852
+ api.Cache.Remove(GetCacheKey(entityId));
853
+ return [2 /*return*/];
854
+ }
855
+ });
856
+ });
857
+ }
858
+ Entity.Delete = Delete;
859
+ function Update(api, data, override) {
860
+ var _a, _b;
861
+ return __awaiter(this, void 0, void 0, function () {
862
+ var reqUrl;
863
+ return __generator(this, function (_c) {
864
+ switch (_c.label) {
865
+ case 0:
866
+ if (!((_a = data === null || data === void 0 ? void 0 : data.Bruce) === null || _a === void 0 ? void 0 : _a["EntityType.ID"])) {
867
+ throw ("Entity Type ID is required.");
868
+ }
869
+ if (!((_b = data === null || data === void 0 ? void 0 : data.Bruce) === null || _b === void 0 ? void 0 : _b.ID)) {
870
+ data.Bruce = __assign(__assign({}, data.Bruce), { ID: ObjectUtils.UId() });
871
+ }
872
+ reqUrl = "entity/" + data.Bruce.ID + "/?dataoverride=" + override + "&BruceEntityType=" + data.Bruce["EntityType.ID"];
873
+ return [4 /*yield*/, api.POST(reqUrl, data, Api.PrepReqParams())];
874
+ case 1:
875
+ data = _c.sent();
876
+ api.Cache.Remove(GetCacheKey(data.Bruce.ID));
877
+ return [2 /*return*/, data];
878
+ }
879
+ });
880
+ });
881
+ }
882
+ Entity.Update = Update;
883
+ function RemoveTag(data, tagId) {
884
+ var _a;
885
+ var tags = (_a = data.Bruce["Layer.ID"]) !== null && _a !== void 0 ? _a : [];
886
+ var index = tags.indexOf(tagId);
887
+ if (index >= 0) {
888
+ tags.splice(index, 1);
889
+ data.Bruce["Layer.ID"] = tags;
890
+ }
891
+ }
892
+ Entity.RemoveTag = RemoveTag;
893
+ function AddTag(data, tagId) {
894
+ var _a;
895
+ var tags = (_a = data.Bruce["Layer.ID"]) !== null && _a !== void 0 ? _a : [];
896
+ if (!tags.includes(tagId)) {
897
+ tags.push(tagId);
898
+ data.Bruce["Layer.ID"] = tags;
899
+ }
900
+ }
901
+ Entity.AddTag = AddTag;
902
+ function SetValue(data, path, value) {
903
+ var curData = data;
904
+ for (var i = 0; i < path.length; i++) {
905
+ var step = path[i];
906
+ if (!curData[step] || typeof curData[step] != "object") {
907
+ curData[step] = {};
908
+ }
909
+ if (i >= path.length - 1) {
910
+ curData[step] = value;
911
+ break;
912
+ }
913
+ curData = curData[step];
914
+ }
915
+ }
916
+ Entity.SetValue = SetValue;
917
+ function GetValue(data, path) {
918
+ var curData = data;
919
+ for (var i = 0; i < path.length; i++) {
920
+ var step = path[i];
921
+ if (!curData[step]) {
922
+ return null;
923
+ }
924
+ if (i >= path.length - 1) {
925
+ return curData[step];
926
+ }
927
+ curData = curData[step];
928
+ }
929
+ return null;
930
+ }
931
+ Entity.GetValue = GetValue;
932
+ var Filter;
933
+ (function (Filter) {
934
+ var V1;
935
+ (function (V1) {
936
+ function GetList(api, filter) {
937
+ return __awaiter(this, void 0, void 0, function () {
938
+ var requestFilter, url, data, entities, i, entity, id;
939
+ return __generator(this, function (_a) {
940
+ switch (_a.label) {
941
+ case 0:
942
+ if (!(filter === null || filter === void 0 ? void 0 : filter.entityTypeId)) {
943
+ throw ("Entity Type ID is required.");
944
+ }
945
+ requestFilter = {};
946
+ if (filter.entityTypeConditions) {
947
+ requestFilter = __assign({}, filter.entityTypeConditions);
948
+ }
949
+ if (filter.layerIds != null && filter.layerIds.length > 0) {
950
+ requestFilter["Bruce.Layer.ID"] = {
951
+ equals: filter.layerIds
952
+ };
953
+ }
954
+ if (filter.bounds) {
955
+ requestFilter["geometry"] = {
956
+ "intersects": [
957
+ filter.bounds.south,
958
+ filter.bounds.north,
959
+ filter.bounds.west,
960
+ filter.bounds.east
961
+ ]
962
+ };
963
+ }
964
+ url = "entities" +
965
+ (
966
+ // Page size and index.
967
+ "?PageSize=" + filter.pageSize + "&PageIndex=" + filter.pageIndex) +
968
+ // Entity type id.
969
+ (filter.entityTypeId ? "&BruceEntityType=" + filter.entityTypeId : "") +
970
+ // Lod.
971
+ (filter.lodCategoryId ? "&LODType=" + filter.lodCategoryId : "") +
972
+ // Attribute filter.
973
+ (!requestFilter ? "" : "&Filter=" + Api.Encode(JSON.stringify(requestFilter))) +
974
+ // Order by attribute + sort order.
975
+ (!filter.orderBy ? "" : "&OrderBy=" + Api.Encode(JSON.stringify(filter.orderBy))) +
976
+ (filter.sortOrder ? "&SortOrder=" + (filter.sortOrder == Api.ESortOrder.Asc ? "ASC" : "DESC") : "");
977
+ return [4 /*yield*/, api.GET(url, Api.PrepReqParams())];
978
+ case 1:
979
+ data = _a.sent();
980
+ entities = data.Items;
981
+ for (i = 0; i < entities.length; i++) {
982
+ entity = entities[i];
983
+ id = entity.Bruce.ID;
984
+ api.Cache.Set(GetCacheKey(id), entity, Api.DEFAULT_CACHE_DURATION);
985
+ }
986
+ return [2 /*return*/, entities];
987
+ }
988
+ });
989
+ });
990
+ }
991
+ V1.GetList = GetList;
992
+ })(V1 = Filter.V1 || (Filter.V1 = {}));
993
+ // TODO: Helpers for constructing the filter.
994
+ })(Filter = Entity.Filter || (Entity.Filter = {}));
995
+ })(Entity || (Entity = {}));
996
+
997
+ var PathUtils;
998
+ (function (PathUtils) {
999
+ function Parse(str) {
1000
+ if (!str) {
1001
+ return [];
1002
+ }
1003
+ var broken = str.split("\"/\"");
1004
+ if (broken.length > 0) {
1005
+ var top_1 = broken[0];
1006
+ if (top_1.length > 0) {
1007
+ if (top_1.charAt(0) == "\"") {
1008
+ top_1 = top_1.substring(1);
1009
+ }
1010
+ broken[0] = top_1;
1011
+ }
1012
+ var endIndex = broken.length - 1;
1013
+ var bot = broken[endIndex];
1014
+ if (bot.length > 0) {
1015
+ if (bot.charAt(bot.length - 1) == "\"") {
1016
+ bot = bot.substring(0, bot.length - 1);
1017
+ }
1018
+ broken[endIndex] = bot;
1019
+ }
1020
+ }
1021
+ return broken;
1022
+ }
1023
+ PathUtils.Parse = Parse;
1024
+ function Wrap(path) {
1025
+ var tmp = "\"";
1026
+ for (var i = 0; i < path.length; i++) {
1027
+ var section = path[i];
1028
+ tmp += section;
1029
+ if (i < path.length - 1) {
1030
+ tmp += "\"/\"";
1031
+ }
1032
+ }
1033
+ tmp += "\"";
1034
+ return tmp;
1035
+ }
1036
+ PathUtils.Wrap = Wrap;
1037
+ function ParseLegacy(str) {
1038
+ var broken = str.split(".");
1039
+ for (var i = 0; i < broken.length; i++) {
1040
+ var piece = broken[0];
1041
+ if (piece.charAt(0) == "\"") {
1042
+ piece = broken[0] = piece.substring(1);
1043
+ }
1044
+ if (piece.charAt(piece.length - 1) == "\"") {
1045
+ broken[0] = piece.substring(0, piece.length - 1);
1046
+ }
1047
+ }
1048
+ return broken;
1049
+ }
1050
+ PathUtils.ParseLegacy = ParseLegacy;
1051
+ })(PathUtils || (PathUtils = {}));
1052
+
1053
+ function getVariable(str) {
1054
+ var start = str.indexOf("${");
1055
+ if (start > -1) {
1056
+ var end = str.indexOf("}");
1057
+ if (end > -1) {
1058
+ if (start < end) {
1059
+ return { path: str.substring(start + 2, end), text: str.substring(start, end) };
1060
+ }
1061
+ }
1062
+ }
1063
+ return null;
1064
+ }
1065
+ var BruceVariable;
1066
+ (function (BruceVariable) {
1067
+ function SwapValues(str, data, legacyParse) {
1068
+ if (!legacyParse) {
1069
+ legacyParse = false;
1070
+ }
1071
+ while (true) {
1072
+ var variable = getVariable(str);
1073
+ if (variable) {
1074
+ var path = legacyParse ? PathUtils.ParseLegacy(variable.path) : PathUtils.Parse(variable.path);
1075
+ var value = "";
1076
+ if (path.length > 0) {
1077
+ value = Entity.GetValue(data, path);
1078
+ }
1079
+ str = str.replace(variable.text, value);
1080
+ }
1081
+ else {
1082
+ break;
1083
+ }
1084
+ }
1085
+ return str;
1086
+ }
1087
+ BruceVariable.SwapValues = SwapValues;
1088
+ })(BruceVariable || (BruceVariable = {}));
1089
+
1090
+ var Calculator;
1091
+ (function (Calculator) {
1092
+ var EValueType;
1093
+ (function (EValueType) {
1094
+ EValueType[EValueType["Color"] = 0] = "Color";
1095
+ EValueType[EValueType["Input"] = 1] = "Input";
1096
+ EValueType[EValueType["Gradient"] = 2] = "Gradient";
1097
+ EValueType[EValueType["Mapping"] = 3] = "Mapping";
1098
+ EValueType[EValueType["TagColor"] = 4] = "TagColor";
1099
+ EValueType[EValueType["RandomColor"] = 5] = "RandomColor";
1100
+ })(EValueType = Calculator.EValueType || (Calculator.EValueType = {}));
1101
+ function GetValue(fields, entity, tags) {
1102
+ if (!tags) {
1103
+ tags = [];
1104
+ }
1105
+ if (!entity) {
1106
+ entity = {};
1107
+ }
1108
+ for (var i = 0; i < fields.length; i++) {
1109
+ var field = fields[i];
1110
+ var value = void 0;
1111
+ switch (field.type) {
1112
+ case EValueType.Color:
1113
+ value = field.value;
1114
+ break;
1115
+ case EValueType.Gradient:
1116
+ value = GetGradientValue(field.value, entity);
1117
+ break;
1118
+ case EValueType.Input:
1119
+ value = GetInputValue(field.value, entity);
1120
+ break;
1121
+ case EValueType.Mapping:
1122
+ value = GetMappingValue(field.value, entity);
1123
+ break;
1124
+ case EValueType.RandomColor:
1125
+ value = Color.RandomColor();
1126
+ break;
1127
+ case EValueType.TagColor:
1128
+ for (var i_1 = 0; i_1 < tags.length; i_1++) {
1129
+ var tag = tags[i_1];
1130
+ if (tag.Color) {
1131
+ value = Color.ColorFromStr(tag.Color);
1132
+ break;
1133
+ }
1134
+ }
1135
+ break;
1136
+ }
1137
+ if (!value || value == 0) {
1138
+ return value;
1139
+ }
1140
+ }
1141
+ return null;
1142
+ }
1143
+ Calculator.GetValue = GetValue;
1144
+ function GetMappingValue(value, entity) {
1145
+ var attrPath = PathUtils.Parse(value.field);
1146
+ var eValue = +Entity.GetValue(entity, attrPath);
1147
+ for (var i = 0; i < value.values.length; i++) {
1148
+ var option = value.values[i];
1149
+ var mapValue = option.fieldValue;
1150
+ if (+mapValue == eValue) {
1151
+ return option.appliedValue;
1152
+ }
1153
+ var mapSplit = mapValue.split("-");
1154
+ if (mapSplit.length == 2) {
1155
+ var min = mapSplit[0];
1156
+ var max = mapSplit[1];
1157
+ if (min != "") {
1158
+ if (eValue < +min) {
1159
+ continue;
1160
+ }
1161
+ }
1162
+ if (max != "") {
1163
+ if (eValue > +max) {
1164
+ continue;
1165
+ }
1166
+ }
1167
+ if (min == "" && max == "") {
1168
+ continue;
1169
+ }
1170
+ return option.appliedValue;
1171
+ }
1172
+ }
1173
+ return null;
1174
+ }
1175
+ Calculator.GetMappingValue = GetMappingValue;
1176
+ function GetGradientValue(value, entity) {
1177
+ var attrPath = PathUtils.Parse(value.field);
1178
+ var eValue = Entity.GetValue(entity, attrPath);
1179
+ eValue = Math.min(Math.max(eValue, value.min), value.max);
1180
+ if (eValue < value.points[0].position) {
1181
+ return Color.ColorFromStr(value.points[0].color);
1182
+ }
1183
+ for (var i = 0; i < value.points.length - 1; i++) {
1184
+ var pointA = value.points[i];
1185
+ var pointB = value.points[i + 1];
1186
+ if (eValue >= pointA.position && eValue <= pointB.position) {
1187
+ if (pointA.position == pointB.position) {
1188
+ return Color.ColorFromStr(pointA.color);
1189
+ }
1190
+ var distance = (eValue - pointA.position) / (pointB.position - pointA.position);
1191
+ var colorA = Color.ColorFromStr(pointA.color);
1192
+ var colorB = Color.ColorFromStr(pointB.color);
1193
+ return {
1194
+ red: colorA.red + (colorB.red - colorA.red) * distance,
1195
+ green: colorA.green + (colorB.green - colorA.green) * distance,
1196
+ blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
1197
+ alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
1198
+ };
1199
+ }
1200
+ }
1201
+ return Color.ColorFromStr(value.points[value.points.length - 1].color);
1202
+ }
1203
+ Calculator.GetGradientValue = GetGradientValue;
1204
+ function GetInputValue(value, entity) {
1205
+ if (typeof value == "string") {
1206
+ try {
1207
+ value = BruceVariable.SwapValues(value, entity);
1208
+ return eval(value);
1209
+ }
1210
+ catch (e) {
1211
+ console.error(e);
1212
+ }
1213
+ }
1214
+ return value;
1215
+ }
1216
+ Calculator.GetInputValue = GetInputValue;
1217
+ })(Calculator || (Calculator = {}));
1218
+
1219
+ var BruceEvent = /** @class */ (function () {
1220
+ function BruceEvent() {
1221
+ // Counter to help differentiate subscriptions.
1222
+ this._counter = 0;
1223
+ // Record of all callback subscriptions for this event.
1224
+ this.callbacks = [];
1225
+ }
1226
+ BruceEvent.prototype.Subscribe = function (callback) {
1227
+ var _this = this;
1228
+ var id = this._counter++;
1229
+ var newBruceEventCallback = {
1230
+ _id: id,
1231
+ removeCallback: function () {
1232
+ _this.Unsubscribe(id);
1233
+ },
1234
+ callback: callback
1235
+ };
1236
+ this.callbacks.push(newBruceEventCallback);
1237
+ return newBruceEventCallback.removeCallback;
1238
+ };
1239
+ BruceEvent.prototype.Unsubscribe = function (id) {
1240
+ var index = this.callbacks.findIndex(function (x) { return x._id == id; });
1241
+ if (index > -1) {
1242
+ this.callbacks.splice(index, 1);
1243
+ }
1244
+ };
1245
+ BruceEvent.prototype.Trigger = function (data) {
1246
+ var callbacks = this.callbacks;
1247
+ for (var i = 0; i < callbacks.length; i++) {
1248
+ var callback = callbacks[i];
1249
+ if (callback.callback) {
1250
+ callback.callback(data);
1251
+ }
1252
+ }
1253
+ };
1254
+ BruceEvent.prototype.Clear = function () {
1255
+ this.callbacks = [];
1256
+ };
1257
+ return BruceEvent;
1258
+ }());
1259
+
1260
+ var Camera;
1261
+ (function (Camera) {
1262
+ var EFrustum;
1263
+ (function (EFrustum) {
1264
+ EFrustum[EFrustum["Perspective"] = 0] = "Perspective";
1265
+ EFrustum[EFrustum["Orthographic"] = 1] = "Orthographic";
1266
+ })(EFrustum = Camera.EFrustum || (Camera.EFrustum = {}));
1267
+ })(Camera || (Camera = {}));
1268
+
1269
+ var Cartes;
1270
+ (function (Cartes) {
1271
+ function ValidateCartes2(cartes) {
1272
+ if (!cartes) {
1273
+ return false;
1274
+ }
1275
+ else if (!cartes.x && cartes.x != 0) {
1276
+ return false;
1277
+ }
1278
+ else if (!cartes.y && cartes.y != 0) {
1279
+ return false;
1280
+ }
1281
+ return true;
1282
+ }
1283
+ Cartes.ValidateCartes2 = ValidateCartes2;
1284
+ function ValidateCartes3(cartes) {
1285
+ if (!ValidateCartes2(cartes)) {
1286
+ return false;
1287
+ }
1288
+ else if (!cartes.z && cartes.z != 0) {
1289
+ return false;
1290
+ }
1291
+ return true;
1292
+ }
1293
+ Cartes.ValidateCartes3 = ValidateCartes3;
1294
+ function IsEqualCartes2(a, b) {
1295
+ if (a.x != b.x) {
1296
+ return false;
1297
+ }
1298
+ else if (a.y != b.y) {
1299
+ return false;
1300
+ }
1301
+ return true;
1302
+ }
1303
+ Cartes.IsEqualCartes2 = IsEqualCartes2;
1304
+ function IsEqualCartes3(a, b) {
1305
+ if (!IsEqualCartes2(a, b)) {
1306
+ return false;
1307
+ }
1308
+ else if (a.z != b.z) {
1309
+ return false;
1310
+ }
1311
+ return true;
1312
+ }
1313
+ Cartes.IsEqualCartes3 = IsEqualCartes3;
1314
+ })(Cartes || (Cartes = {}));
1315
+
1316
+ var Carto;
1317
+ (function (Carto) {
1318
+ function ValidateCarto(carto) {
1319
+ if (!carto) {
1320
+ return false;
1321
+ }
1322
+ else if (!carto.longitude && carto.longitude != 0) {
1323
+ return false;
1324
+ }
1325
+ else if (!carto.latitude && carto.latitude != 0) {
1326
+ return false;
1327
+ }
1328
+ return true;
1329
+ }
1330
+ Carto.ValidateCarto = ValidateCarto;
1331
+ function IsEqual(a, b) {
1332
+ if (a.longitude != b.longitude) {
1333
+ return false;
1334
+ }
1335
+ else if (a.latitude != b.latitude) {
1336
+ return false;
1337
+ }
1338
+ return true;
1339
+ }
1340
+ Carto.IsEqual = IsEqual;
1341
+ })(Carto || (Carto = {}));
1342
+
1343
+ var DelayQueue = /** @class */ (function () {
1344
+ function DelayQueue(callback, delay) {
1345
+ if (delay === void 0) { delay = 200; }
1346
+ // Millisecond delay.
1347
+ this.delay = 200;
1348
+ // Date-time stamp for the last callback call.
1349
+ this.lastCallTime = null;
1350
+ this.callback = callback;
1351
+ this.delay = delay;
1352
+ }
1353
+ DelayQueue.prototype.Call = function (force) {
1354
+ var _this = this;
1355
+ if (force === void 0) { force = false; }
1356
+ if (this.lastCallTime == null) {
1357
+ force = true;
1358
+ }
1359
+ if (force) {
1360
+ var endDate = new Date().getTime();
1361
+ this.doCall(endDate);
1362
+ }
1363
+ else {
1364
+ var endDate = new Date().getTime();
1365
+ var seconds = (endDate - this.lastCallTime) / 1000;
1366
+ var delay = this.delay / 1000;
1367
+ if (seconds > delay) {
1368
+ this.doCall(endDate);
1369
+ }
1370
+ else if (this.delayTimeout == null) {
1371
+ var diff = (delay - seconds) * 1000;
1372
+ this.delayTimeout = setTimeout(function () {
1373
+ _this.delayTimeout = null;
1374
+ _this.Call();
1375
+ }, diff + 0.02);
1376
+ }
1377
+ }
1378
+ };
1379
+ DelayQueue.prototype.doCall = function (endDate) {
1380
+ if (this.delayTimeout != null) {
1381
+ clearTimeout(this.delayTimeout);
1382
+ this.delayTimeout = null;
1383
+ }
1384
+ this.lastCallTime = endDate;
1385
+ this.callback();
1386
+ };
1387
+ DelayQueue.prototype.Dispose = function () {
1388
+ if (this.delayTimeout != null) {
1389
+ clearTimeout(this.delayTimeout);
1390
+ this.delayTimeout = null;
1391
+ }
1392
+ };
1393
+ return DelayQueue;
1394
+ }());
1395
+
1396
+ var Geometry;
1397
+ (function (Geometry) {
1398
+ function LineStrFromPoints(points) {
1399
+ if (!points.length) {
1400
+ throw ("points is empty.");
1401
+ }
1402
+ var carto = points[0];
1403
+ var lineString = carto.longitude + "," + carto.latitude + (carto.altitude != null ? "," + carto.altitude : "");
1404
+ for (var i = 1; i < points.length; i++) {
1405
+ carto = points[i];
1406
+ lineString += " " + carto.longitude + "," + carto.latitude + (carto.altitude != null ? "," + carto.altitude : "");
1407
+ }
1408
+ return lineString;
1409
+ }
1410
+ Geometry.LineStrFromPoints = LineStrFromPoints;
1411
+ function RemoveRepeatPoints(positions) {
1412
+ var filteredList = [];
1413
+ for (var i = 0; i < positions.length; i++) {
1414
+ var pos = positions[i];
1415
+ var lastPos = filteredList.length > 0 ? filteredList[filteredList.length - 1] : null;
1416
+ if (!lastPos || (pos.latitude != lastPos.latitude || pos.longitude != lastPos.longitude || pos.altitude != lastPos.altitude)) {
1417
+ filteredList.push(pos);
1418
+ }
1419
+ }
1420
+ return filteredList;
1421
+ }
1422
+ Geometry.RemoveRepeatPoints = RemoveRepeatPoints;
1423
+ function ParsePoints(data) {
1424
+ data = data.replace(/[^\d.,-\s]/g, "");
1425
+ var splitterCoordinates = " ";
1426
+ var splitterAxis = ",";
1427
+ var commaIndex = data.indexOf(",");
1428
+ var spaceIndex = data.indexOf(" ");
1429
+ if ((spaceIndex > -1 && commaIndex > spaceIndex) || commaIndex <= -1) {
1430
+ splitterCoordinates = ",";
1431
+ splitterAxis = " ";
1432
+ }
1433
+ var points = data.trim().split(splitterCoordinates);
1434
+ points = points.filter(function (a) { return a != ""; });
1435
+ var result = [];
1436
+ for (var i = 0; i < points.length; i++) {
1437
+ var pointData = points[i];
1438
+ var coords = pointData.trim().split(splitterAxis);
1439
+ if (coords.length == 2 || coords.length == 3) {
1440
+ var longitude = +coords[0];
1441
+ var latitude = +coords[1];
1442
+ var altitude = coords.length >= 3 ? +coords[2] : 0;
1443
+ if (longitude != null && latitude != null) {
1444
+ result.push({
1445
+ altitude: altitude,
1446
+ latitude: latitude,
1447
+ longitude: longitude
1448
+ });
1449
+ }
1450
+ else {
1451
+ console.warn("Invalid point data detected.", pointData);
1452
+ }
1453
+ }
1454
+ }
1455
+ return result;
1456
+ }
1457
+ Geometry.ParsePoints = ParsePoints;
1458
+ function ParseGeometry(geometry) {
1459
+ if (typeof geometry == "string") {
1460
+ var positions = [];
1461
+ var geometryParsed = (geometry || "").split(";");
1462
+ for (var i = 0; i < geometryParsed.length; i++) {
1463
+ var data = geometryParsed[i];
1464
+ var points = ParsePoints(data);
1465
+ if (points && points.length > 0) {
1466
+ positions = positions.concat(points);
1467
+ }
1468
+ }
1469
+ positions = RemoveRepeatPoints(positions);
1470
+ var newGeometry = {};
1471
+ if (positions.length > 0) {
1472
+ var topPoint = positions[0];
1473
+ newGeometry.Point = topPoint.latitude + "," + topPoint.longitude + (topPoint.altitude != null ? "," + topPoint.altitude : "");
1474
+ if (positions.length > 1) {
1475
+ newGeometry.Polygon = [{ Facing: "out", LinearRing: LineStrFromPoints(positions) }];
1476
+ }
1477
+ if (positions.length > 2) {
1478
+ newGeometry.LineString = LineStrFromPoints(positions);
1479
+ }
1480
+ }
1481
+ return newGeometry;
1482
+ }
1483
+ return geometry;
1484
+ }
1485
+ Geometry.ParseGeometry = ParseGeometry;
1486
+ })(Geometry || (Geometry = {}));
1487
+
1488
+ var UTC;
1489
+ (function (UTC) {
1490
+ var EMonth;
1491
+ (function (EMonth) {
1492
+ EMonth[EMonth["January"] = 1] = "January";
1493
+ EMonth[EMonth["February"] = 2] = "February";
1494
+ EMonth[EMonth["March"] = 3] = "March";
1495
+ EMonth[EMonth["April"] = 4] = "April";
1496
+ EMonth[EMonth["May"] = 5] = "May";
1497
+ EMonth[EMonth["June"] = 6] = "June";
1498
+ EMonth[EMonth["July"] = 7] = "July";
1499
+ EMonth[EMonth["August"] = 8] = "August";
1500
+ EMonth[EMonth["September"] = 9] = "September";
1501
+ EMonth[EMonth["October"] = 10] = "October";
1502
+ EMonth[EMonth["November"] = 11] = "November";
1503
+ EMonth[EMonth["December"] = 12] = "December";
1504
+ })(EMonth = UTC.EMonth || (UTC.EMonth = {}));
1505
+ function ToDate(utc) {
1506
+ return new Date(utc.y, utc.m - 1, utc.d, utc.hh, utc.mm, utc.ss, 0);
1507
+ }
1508
+ UTC.ToDate = ToDate;
1509
+ function FromDate(date) {
1510
+ return {
1511
+ y: date.getUTCFullYear(),
1512
+ m: date.getUTCMonth() + 1,
1513
+ d: date.getUTCDate(),
1514
+ hh: date.getUTCHours(),
1515
+ mm: date.getUTCMinutes(),
1516
+ ss: date.getUTCSeconds()
1517
+ };
1518
+ }
1519
+ UTC.FromDate = FromDate;
1520
+ })(UTC || (UTC = {}));
1521
+
1522
+ var EntityAttachmentType;
1523
+ (function (EntityAttachmentType) {
1524
+ function GetCacheKey(id) {
1525
+ return Api.ECacheKey.AttachmentType + Api.ECacheKey.Id + id;
1526
+ }
1527
+ EntityAttachmentType.GetCacheKey = GetCacheKey;
1528
+ function GetListCacheKey() {
1529
+ return Api.ECacheKey.AttachmentType;
1530
+ }
1531
+ EntityAttachmentType.GetListCacheKey = GetListCacheKey;
1532
+ var EType;
1533
+ (function (EType) {
1534
+ EType["Photo"] = "photo";
1535
+ EType["Document"] = "document";
1536
+ EType["Video"] = "video";
1537
+ EType["Drawing"] = "drawing";
1538
+ EType["Model"] = "model";
1539
+ })(EType = EntityAttachmentType.EType || (EntityAttachmentType.EType = {}));
1540
+ function Delete(api, id) {
1541
+ return __awaiter(this, void 0, void 0, function () {
1542
+ return __generator(this, function (_a) {
1543
+ switch (_a.label) {
1544
+ case 0:
1545
+ if (!id) {
1546
+ throw ("Type ID is required.");
1547
+ }
1548
+ return [4 /*yield*/, api.DELETE("entityAttachmentType/" + id, Api.PrepReqParams())];
1549
+ case 1:
1550
+ _a.sent();
1551
+ api.Cache.Remove(GetCacheKey(id));
1552
+ api.Cache.Remove(GetListCacheKey());
1553
+ return [2 /*return*/];
1554
+ }
1555
+ });
1556
+ });
1557
+ }
1558
+ EntityAttachmentType.Delete = Delete;
1559
+ function Update(api, data) {
1560
+ return __awaiter(this, void 0, void 0, function () {
1561
+ return __generator(this, function (_a) {
1562
+ switch (_a.label) {
1563
+ case 0:
1564
+ if (!(data === null || data === void 0 ? void 0 : data.ID)) {
1565
+ throw ("Type ID is required.");
1566
+ }
1567
+ return [4 /*yield*/, api.post("entityAttachmentType/" + data.ID, data, Api.PrepReqParams())];
1568
+ case 1:
1569
+ data = _a.sent();
1570
+ api.Cache.Remove(GetCacheKey(data.ID));
1571
+ api.Cache.Remove(GetListCacheKey());
1572
+ return [2 /*return*/, data];
1573
+ }
1574
+ });
1575
+ });
1576
+ }
1577
+ EntityAttachmentType.Update = Update;
1578
+ function GetList(api) {
1579
+ return __awaiter(this, void 0, void 0, function () {
1580
+ var cacheData, req;
1581
+ var _this = this;
1582
+ return __generator(this, function (_a) {
1583
+ cacheData = api.Cache.Get(GetListCacheKey());
1584
+ if (cacheData) {
1585
+ return [2 /*return*/, cacheData];
1586
+ }
1587
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
1588
+ var data, e_1;
1589
+ return __generator(this, function (_a) {
1590
+ switch (_a.label) {
1591
+ case 0:
1592
+ _a.trys.push([0, 2, , 3]);
1593
+ return [4 /*yield*/, api.GET("entityAttachmentTypes", Api.PrepReqParams())];
1594
+ case 1:
1595
+ data = _a.sent();
1596
+ res(data.Items);
1597
+ return [3 /*break*/, 3];
1598
+ case 2:
1599
+ e_1 = _a.sent();
1600
+ rej(e_1);
1601
+ return [3 /*break*/, 3];
1602
+ case 3: return [2 /*return*/];
1603
+ }
1604
+ });
1605
+ }); });
1606
+ api.Cache.Set(GetListCacheKey(), req);
1607
+ return [2 /*return*/, req];
1608
+ });
1609
+ });
1610
+ }
1611
+ EntityAttachmentType.GetList = GetList;
1612
+ })(EntityAttachmentType || (EntityAttachmentType = {}));
1613
+
1614
+ var EntityAttachment;
1615
+ (function (EntityAttachment) {
1616
+ function GetCacheKey(entityId, typeId, fileId) {
1617
+ return Api.ECacheKey.Attachment + Api.ECacheKey.Id + entityId + Api.ECacheKey.Id + typeId + Api.ECacheKey.Id + fileId;
1618
+ }
1619
+ EntityAttachment.GetCacheKey = GetCacheKey;
1620
+ function GetListCacheKey(entityId) {
1621
+ return Api.ECacheKey.Attachment + Api.ECacheKey.Entity + Api.ECacheKey.Id + entityId;
1622
+ }
1623
+ EntityAttachment.GetListCacheKey = GetListCacheKey;
1624
+ function Update(api, data) {
1625
+ return __awaiter(this, void 0, void 0, function () {
1626
+ var url;
1627
+ return __generator(this, function (_a) {
1628
+ switch (_a.label) {
1629
+ case 0:
1630
+ if (!(data === null || data === void 0 ? void 0 : data["Entity.ID"]) || !(data === null || data === void 0 ? void 0 : data["EntityAttachmentType.ID"]) || !(data === null || data === void 0 ? void 0 : data["ClientFile.ID"])) {
1631
+ throw ("Entity ID, Type ID, and File ID are required.");
1632
+ }
1633
+ url = "entity/" + data["Entity.ID"] + "/attachment/" + data["EntityAttachmentType.ID"] + "/" + data["ClientFile.ID"];
1634
+ return [4 /*yield*/, api.POST(url, data, Api.PrepReqParams())];
1635
+ case 1:
1636
+ data = _a.sent();
1637
+ api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
1638
+ api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
1639
+ return [2 /*return*/, data];
1640
+ }
1641
+ });
1642
+ });
1643
+ }
1644
+ EntityAttachment.Update = Update;
1645
+ function UpdateOrder(api, entityId, typeId, fileIds) {
1646
+ return __awaiter(this, void 0, void 0, function () {
1647
+ var reqData, i;
1648
+ return __generator(this, function (_a) {
1649
+ switch (_a.label) {
1650
+ case 0:
1651
+ if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
1652
+ throw ("Entity ID, Type ID, and File IDs are required.");
1653
+ }
1654
+ reqData = {
1655
+ "DisplayOrder.Start": 0,
1656
+ "ClientFile.ID": fileIds
1657
+ };
1658
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/attachments/" + typeId + "/setOrder", reqData, Api.PrepReqParams())];
1659
+ case 1:
1660
+ _a.sent();
1661
+ for (i = 0; i < fileIds.length; i++) {
1662
+ api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
1663
+ }
1664
+ api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
1665
+ return [2 /*return*/];
1666
+ }
1667
+ });
1668
+ });
1669
+ }
1670
+ EntityAttachment.UpdateOrder = UpdateOrder;
1671
+ function Delete(api, data) {
1672
+ return __awaiter(this, void 0, void 0, function () {
1673
+ var reqData;
1674
+ return __generator(this, function (_a) {
1675
+ switch (_a.label) {
1676
+ case 0:
1677
+ if (!(data === null || data === void 0 ? void 0 : data["Entity.ID"]) || !(data === null || data === void 0 ? void 0 : data["EntityAttachmentType.ID"]) || !(data === null || data === void 0 ? void 0 : data["ClientFile.ID"])) {
1678
+ throw ("Entity ID, Type ID, and File ID are required.");
1679
+ }
1680
+ reqData = {
1681
+ "ClientFile.ID": [data["ClientFile.ID"]]
1682
+ };
1683
+ return [4 /*yield*/, api.POST("entity/" + data["Entity.ID"] + "/attachments/" + data["EntityAttachmentType.ID"] + "/delete", reqData, Api.PrepReqParams())];
1684
+ case 1:
1685
+ _a.sent();
1686
+ api.Cache.Remove(GetCacheKey(data["Entity.ID"], data["EntityAttachmentType.ID"], data["ClientFile.ID"]));
1687
+ api.Cache.RemoveByStartsWith(GetListCacheKey(data["Entity.ID"]));
1688
+ return [2 /*return*/];
1689
+ }
1690
+ });
1691
+ });
1692
+ }
1693
+ EntityAttachment.Delete = Delete;
1694
+ function DeleteByFileIds(api, entityId, typeId, fileIds) {
1695
+ return __awaiter(this, void 0, void 0, function () {
1696
+ var reqData, i;
1697
+ return __generator(this, function (_a) {
1698
+ switch (_a.label) {
1699
+ case 0:
1700
+ if (!entityId || !typeId || !(fileIds === null || fileIds === void 0 ? void 0 : fileIds.length)) {
1701
+ throw ("Entity ID, Type ID, and File IDs are required.");
1702
+ }
1703
+ reqData = {
1704
+ "ClientFile.ID": fileIds
1705
+ };
1706
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/attachments/" + typeId + "/delete", reqData, Api.PrepReqParams())];
1707
+ case 1:
1708
+ _a.sent();
1709
+ for (i = 0; i < fileIds.length; i++) {
1710
+ api.Cache.Remove(GetCacheKey(entityId, typeId, fileIds[i]));
1711
+ }
1712
+ api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
1713
+ return [2 /*return*/];
1714
+ }
1715
+ });
1716
+ });
1717
+ }
1718
+ EntityAttachment.DeleteByFileIds = DeleteByFileIds;
1719
+ function GetListByEntityId(api, entityId) {
1720
+ return __awaiter(this, void 0, void 0, function () {
1721
+ var cacheData, req;
1722
+ var _this = this;
1723
+ return __generator(this, function (_a) {
1724
+ if (!entityId) {
1725
+ throw ("Entity ID is required.");
1726
+ }
1727
+ cacheData = api.Cache.Get(GetListCacheKey(entityId));
1728
+ if (cacheData) {
1729
+ return [2 /*return*/, cacheData];
1730
+ }
1731
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
1732
+ var data, e_1;
1733
+ return __generator(this, function (_a) {
1734
+ switch (_a.label) {
1735
+ case 0:
1736
+ _a.trys.push([0, 2, , 3]);
1737
+ return [4 /*yield*/, api.GET("entity/" + entityId + "/attachments", Api.PrepReqParams())];
1738
+ case 1:
1739
+ data = _a.sent();
1740
+ res(data.Items);
1741
+ return [3 /*break*/, 3];
1742
+ case 2:
1743
+ e_1 = _a.sent();
1744
+ rej(e_1);
1745
+ return [3 /*break*/, 3];
1746
+ case 3: return [2 /*return*/];
1747
+ }
1748
+ });
1749
+ }); });
1750
+ api.Cache.Set(GetListCacheKey(entityId), req);
1751
+ return [2 /*return*/, req];
1752
+ });
1753
+ });
1754
+ }
1755
+ EntityAttachment.GetListByEntityId = GetListByEntityId;
1756
+ function Upload(api, file, entityId, typeId, onProgress) {
1757
+ return __awaiter(this, void 0, void 0, function () {
1758
+ var url, req;
1759
+ return __generator(this, function (_a) {
1760
+ switch (_a.label) {
1761
+ case 0:
1762
+ if (!entityId || !typeId || !file) {
1763
+ throw ("Entity ID, Type ID, and File are required.");
1764
+ }
1765
+ url = "entity/" + entityId + "/attachment/" + typeId;
1766
+ return [4 /*yield*/, api.UPLOAD(url, file, { onProgress: onProgress })];
1767
+ case 1:
1768
+ req = _a.sent();
1769
+ api.Cache.RemoveByStartsWith(GetListCacheKey(entityId));
1770
+ return [2 /*return*/, req];
1771
+ }
1772
+ });
1773
+ });
1774
+ }
1775
+ EntityAttachment.Upload = Upload;
1776
+ })(EntityAttachment || (EntityAttachment = {}));
1777
+
1778
+ var EntityComment;
1779
+ (function (EntityComment) {
1780
+ function GetCacheKey(id) {
1781
+ return Api.ECacheKey.Comment + Api.ECacheKey.Id + id;
1782
+ }
1783
+ EntityComment.GetCacheKey = GetCacheKey;
1784
+ function GetListCacheKey(entityId) {
1785
+ return Api.ECacheKey.Comment + Api.ECacheKey.Entity + Api.ECacheKey.Id + entityId;
1786
+ }
1787
+ EntityComment.GetListCacheKey = GetListCacheKey;
1788
+ function Update(api, data) {
1789
+ return __awaiter(this, void 0, void 0, function () {
1790
+ var url;
1791
+ return __generator(this, function (_a) {
1792
+ switch (_a.label) {
1793
+ case 0:
1794
+ if (!(data === null || data === void 0 ? void 0 : data["TargetObject.ID"])) {
1795
+ throw ("TargetObject.ID (entity id) is required.");
1796
+ }
1797
+ url = "entity/" + data["TargetObject.ID"] + "/comment" + (data.ID == null ? "" : "/" + data.ID);
1798
+ return [4 /*yield*/, api.POST(url, data, Api.PrepReqParams())];
1799
+ case 1:
1800
+ data = _a.sent();
1801
+ api.Cache.Remove(GetCacheKey(data.ID));
1802
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Comment + Api.ECacheKey.Entity);
1803
+ return [2 /*return*/, data];
1804
+ }
1805
+ });
1806
+ });
1807
+ }
1808
+ EntityComment.Update = Update;
1809
+ function Delete(api, entityId, commentId) {
1810
+ return __awaiter(this, void 0, void 0, function () {
1811
+ return __generator(this, function (_a) {
1812
+ switch (_a.label) {
1813
+ case 0:
1814
+ if (!commentId) {
1815
+ throw ("Comment ID is required.");
1816
+ }
1817
+ return [4 /*yield*/, api.DELETE("entity/" + entityId + "/comment/" + commentId, Api.PrepReqParams())];
1818
+ case 1:
1819
+ _a.sent();
1820
+ api.Cache.Remove(GetCacheKey(commentId));
1821
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Comment + Api.ECacheKey.Entity);
1822
+ return [2 /*return*/];
1823
+ }
1824
+ });
1825
+ });
1826
+ }
1827
+ EntityComment.Delete = Delete;
1828
+ function GetListByEntityId(api, entityId) {
1829
+ return __awaiter(this, void 0, void 0, function () {
1830
+ var cacheData, req;
1831
+ var _this = this;
1832
+ return __generator(this, function (_a) {
1833
+ if (!entityId) {
1834
+ throw ("Entity ID is required.");
1835
+ }
1836
+ cacheData = api.Cache.Get(GetListCacheKey(entityId));
1837
+ if (cacheData) {
1838
+ return [2 /*return*/, cacheData];
1839
+ }
1840
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
1841
+ var data, e_1;
1842
+ return __generator(this, function (_a) {
1843
+ switch (_a.label) {
1844
+ case 0:
1845
+ _a.trys.push([0, 2, , 3]);
1846
+ return [4 /*yield*/, api.GET("entity/" + entityId + "/comments", Api.PrepReqParams())];
1847
+ case 1:
1848
+ data = _a.sent();
1849
+ res(data.Items);
1850
+ return [3 /*break*/, 3];
1851
+ case 2:
1852
+ e_1 = _a.sent();
1853
+ rej(e_1);
1854
+ return [3 /*break*/, 3];
1855
+ case 3: return [2 /*return*/];
1856
+ }
1857
+ });
1858
+ }); });
1859
+ api.Cache.Set(GetListCacheKey(entityId), req);
1860
+ return [2 /*return*/, req];
1861
+ });
1862
+ });
1863
+ }
1864
+ EntityComment.GetListByEntityId = GetListByEntityId;
1865
+ })(EntityComment || (EntityComment = {}));
1866
+
1867
+ var EntityLink;
1868
+ (function (EntityLink) {
1869
+ function GetCacheKey(id) {
1870
+ return Api.ECacheKey.Link + Api.ECacheKey.Id + id;
1871
+ }
1872
+ EntityLink.GetCacheKey = GetCacheKey;
1873
+ function GetListCacheKey(entityId) {
1874
+ return Api.ECacheKey.Link + Api.ECacheKey.Entity + Api.ECacheKey.Id + entityId;
1875
+ }
1876
+ EntityLink.GetListCacheKey = GetListCacheKey;
1877
+ function Update(api, data) {
1878
+ return __awaiter(this, void 0, void 0, function () {
1879
+ var url;
1880
+ return __generator(this, function (_a) {
1881
+ switch (_a.label) {
1882
+ case 0:
1883
+ if (!(data === null || data === void 0 ? void 0 : data["Entity.ID"])) {
1884
+ throw ("Entity ID is required.");
1885
+ }
1886
+ url = "entity/" + data["Entity.ID"] + "/link" + (data.ID == null ? "" : "/" + data.ID);
1887
+ return [4 /*yield*/, api.POST(url, data, Api.PrepReqParams())];
1888
+ case 1:
1889
+ data = _a.sent();
1890
+ api.Cache.Remove(GetCacheKey(data.ID));
1891
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Link + Api.ECacheKey.Entity);
1892
+ return [2 /*return*/, data];
1893
+ }
1894
+ });
1895
+ });
1896
+ }
1897
+ EntityLink.Update = Update;
1898
+ function Delete(api, entityId, linkId) {
1899
+ return __awaiter(this, void 0, void 0, function () {
1900
+ return __generator(this, function (_a) {
1901
+ switch (_a.label) {
1902
+ case 0:
1903
+ if (!linkId) {
1904
+ throw ("Link ID is required.");
1905
+ }
1906
+ return [4 /*yield*/, api.DELETE("entity/" + entityId + "/link/" + linkId, Api.PrepReqParams())];
1907
+ case 1:
1908
+ _a.sent();
1909
+ api.Cache.Remove(GetCacheKey(linkId));
1910
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Link + Api.ECacheKey.Entity);
1911
+ return [2 /*return*/];
1912
+ }
1913
+ });
1914
+ });
1915
+ }
1916
+ EntityLink.Delete = Delete;
1917
+ function GetListByEntityId(api, entityId) {
1918
+ return __awaiter(this, void 0, void 0, function () {
1919
+ var cacheData, req;
1920
+ var _this = this;
1921
+ return __generator(this, function (_a) {
1922
+ if (!entityId) {
1923
+ throw ("Entity ID is required.");
1924
+ }
1925
+ cacheData = api.Cache.Get(GetListCacheKey(entityId));
1926
+ if (cacheData) {
1927
+ return [2 /*return*/, cacheData];
1928
+ }
1929
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
1930
+ var data, e_1;
1931
+ return __generator(this, function (_a) {
1932
+ switch (_a.label) {
1933
+ case 0:
1934
+ _a.trys.push([0, 2, , 3]);
1935
+ return [4 /*yield*/, api.GET("entity/" + entityId + "/links", Api.PrepReqParams())];
1936
+ case 1:
1937
+ data = _a.sent();
1938
+ res(data.Items);
1939
+ return [3 /*break*/, 3];
1940
+ case 2:
1941
+ e_1 = _a.sent();
1942
+ rej(e_1);
1943
+ return [3 /*break*/, 3];
1944
+ case 3: return [2 /*return*/];
1945
+ }
1946
+ });
1947
+ }); });
1948
+ api.Cache.Set(GetListCacheKey(entityId), req);
1949
+ return [2 /*return*/, req];
1950
+ });
1951
+ });
1952
+ }
1953
+ EntityLink.GetListByEntityId = GetListByEntityId;
1954
+ })(EntityLink || (EntityLink = {}));
1955
+
1956
+ var EntityLod;
1957
+ (function (EntityLod) {
1958
+ function GetCacheKey(url) {
1959
+ return Api.ECacheKey.Lod + Api.ECacheKey.Id + url;
1960
+ }
1961
+ EntityLod.GetCacheKey = GetCacheKey;
1962
+ function GetUrl(api, entityId, categoryId, level, strict) {
1963
+ if (!entityId) {
1964
+ throw ("Entity ID is required.");
1965
+ }
1966
+ if (!categoryId) {
1967
+ categoryId = "GLB";
1968
+ }
1969
+ if (!level) {
1970
+ level = 0;
1971
+ }
1972
+ var url = api.GetBaseUrl() + ("entity/" + entityId + "/lod/" + categoryId + "/" + level);
1973
+ if (strict) {
1974
+ url = url + "?strict=true";
1975
+ }
1976
+ return url;
1977
+ }
1978
+ EntityLod.GetUrl = GetUrl;
1979
+ function GetUrlFileId(api, url) {
1980
+ return __awaiter(this, void 0, void 0, function () {
1981
+ var cacheData, req;
1982
+ var _this = this;
1983
+ return __generator(this, function (_a) {
1984
+ if (!url) {
1985
+ throw ("Url is required.");
1986
+ }
1987
+ cacheData = api.Cache.Get(GetCacheKey(url));
1988
+ if (cacheData) {
1989
+ return [2 /*return*/, cacheData];
1990
+ }
1991
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
1992
+ var record, e_1;
1993
+ return __generator(this, function (_a) {
1994
+ switch (_a.label) {
1995
+ case 0:
1996
+ _a.trys.push([0, 2, , 3]);
1997
+ return [4 /*yield*/, api.get(url, Api.PrepReqParams())];
1998
+ case 1:
1999
+ record = _a.sent();
2000
+ res(record["ClientFile.ID"]);
2001
+ return [3 /*break*/, 3];
2002
+ case 2:
2003
+ e_1 = _a.sent();
2004
+ rej(e_1);
2005
+ return [3 /*break*/, 3];
2006
+ case 3: return [2 /*return*/];
2007
+ }
2008
+ });
2009
+ }); });
2010
+ api.Cache.Set(GetCacheKey(url), req, Api.DEFAULT_CACHE_DURATION);
2011
+ return [2 /*return*/, req];
2012
+ });
2013
+ });
2014
+ }
2015
+ EntityLod.GetUrlFileId = GetUrlFileId;
2016
+ function GetLods(api, params) {
2017
+ var _a;
2018
+ return __awaiter(this, void 0, void 0, function () {
2019
+ var data;
2020
+ return __generator(this, function (_b) {
2021
+ switch (_b.label) {
2022
+ case 0:
2023
+ if (!((_a = params === null || params === void 0 ? void 0 : params.Items) === null || _a === void 0 ? void 0 : _a.length)) {
2024
+ throw ("Items are required.");
2025
+ }
2026
+ return [4 /*yield*/, api.POST("entity/getlods", params)];
2027
+ case 1:
2028
+ data = _b.sent();
2029
+ return [2 /*return*/, data.Items];
2030
+ }
2031
+ });
2032
+ });
2033
+ }
2034
+ EntityLod.GetLods = GetLods;
2035
+ })(EntityLod || (EntityLod = {}));
2036
+
2037
+ var EntityRelationType;
2038
+ (function (EntityRelationType) {
2039
+ function GetCacheKey(id) {
2040
+ return Api.ECacheKey.RelationType + Api.ECacheKey.Id + id;
2041
+ }
2042
+ EntityRelationType.GetCacheKey = GetCacheKey;
2043
+ function GetListCacheKey() {
2044
+ return Api.ECacheKey.RelationType;
2045
+ }
2046
+ EntityRelationType.GetListCacheKey = GetListCacheKey;
2047
+ function Get(api, typeId) {
2048
+ return __awaiter(this, void 0, void 0, function () {
2049
+ var key, cacheData, req;
2050
+ return __generator(this, function (_a) {
2051
+ if (!typeId) {
2052
+ throw ("Type ID is required.");
2053
+ }
2054
+ key = GetCacheKey(typeId);
2055
+ cacheData = api.Cache.Get(key);
2056
+ if (cacheData) {
2057
+ return [2 /*return*/, cacheData];
2058
+ }
2059
+ req = api.GET("entityRelationType/" + typeId, Api.PrepReqParams());
2060
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
2061
+ return [2 /*return*/, req];
2062
+ });
2063
+ });
2064
+ }
2065
+ EntityRelationType.Get = Get;
2066
+ function Delete(api, typeId) {
2067
+ return __awaiter(this, void 0, void 0, function () {
2068
+ return __generator(this, function (_a) {
2069
+ switch (_a.label) {
2070
+ case 0:
2071
+ if (!typeId) {
2072
+ throw ("Type ID is required.");
2073
+ }
2074
+ return [4 /*yield*/, api.DELETE("entityRelationType/" + typeId, Api.PrepReqParams())];
2075
+ case 1:
2076
+ _a.sent();
2077
+ api.Cache.Remove(GetCacheKey(typeId));
2078
+ api.Cache.Remove(GetListCacheKey());
2079
+ return [2 /*return*/];
2080
+ }
2081
+ });
2082
+ });
2083
+ }
2084
+ EntityRelationType.Delete = Delete;
2085
+ function GetList(api) {
2086
+ return __awaiter(this, void 0, void 0, function () {
2087
+ var cacheData, req;
2088
+ var _this = this;
2089
+ return __generator(this, function (_a) {
2090
+ cacheData = api.Cache.Get(GetListCacheKey());
2091
+ if (cacheData) {
2092
+ return [2 /*return*/, cacheData];
2093
+ }
2094
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2095
+ var data, e_1;
2096
+ return __generator(this, function (_a) {
2097
+ switch (_a.label) {
2098
+ case 0:
2099
+ _a.trys.push([0, 2, , 3]);
2100
+ return [4 /*yield*/, api.GET("entityRelationTypes", Api.PrepReqParams())];
2101
+ case 1:
2102
+ data = _a.sent();
2103
+ res(data.Items);
2104
+ return [3 /*break*/, 3];
2105
+ case 2:
2106
+ e_1 = _a.sent();
2107
+ rej(e_1);
2108
+ return [3 /*break*/, 3];
2109
+ case 3: return [2 /*return*/];
2110
+ }
2111
+ });
2112
+ }); });
2113
+ api.Cache.Set(GetListCacheKey(), req);
2114
+ return [2 /*return*/, req];
2115
+ });
2116
+ });
2117
+ }
2118
+ EntityRelationType.GetList = GetList;
2119
+ function Update(api, data) {
2120
+ return __awaiter(this, void 0, void 0, function () {
2121
+ return __generator(this, function (_a) {
2122
+ switch (_a.label) {
2123
+ case 0:
2124
+ if (!(data === null || data === void 0 ? void 0 : data.ForwardName) || !(data === null || data === void 0 ? void 0 : data.ReverseName)) {
2125
+ throw ("Forward and reverse names are required.");
2126
+ }
2127
+ if (!data.ID) {
2128
+ data.ID = ObjectUtils.UId();
2129
+ }
2130
+ return [4 /*yield*/, api.post("entityRelationType/" + data.ID, data, Api.PrepReqParams())];
2131
+ case 1:
2132
+ data = _a.sent();
2133
+ api.Cache.Remove(GetCacheKey(data.ID));
2134
+ api.Cache.Remove(GetListCacheKey());
2135
+ return [2 /*return*/, data];
2136
+ }
2137
+ });
2138
+ });
2139
+ }
2140
+ EntityRelationType.Update = Update;
2141
+ })(EntityRelationType || (EntityRelationType = {}));
2142
+
2143
+ var EntityRelation;
2144
+ (function (EntityRelation) {
2145
+ function GetCacheKey(entityA, entityB, typeId) {
2146
+ return "" + Api.ECacheKey.Relation + Api.ECacheKey.Id + entityA + Api.ECacheKey.Id + entityB + Api.ECacheKey.Id + typeId;
2147
+ }
2148
+ EntityRelation.GetCacheKey = GetCacheKey;
2149
+ function GetEntityCacheKey(entityId) {
2150
+ return Api.ECacheKey.Relation + Api.ECacheKey.Entity + Api.ECacheKey.Id + entityId;
2151
+ }
2152
+ EntityRelation.GetEntityCacheKey = GetEntityCacheKey;
2153
+ function GetListCacheKey(params) {
2154
+ return Api.ECacheKey.Relation + Api.ECacheKey.RelationType + Api.ECacheKey.Id + params.typeId + Api.ECacheKey.Id + params.oneWayOnly + Api.ECacheKey.Id + params.loadEntityData;
2155
+ }
2156
+ EntityRelation.GetListCacheKey = GetListCacheKey;
2157
+ function Update(api, data) {
2158
+ return __awaiter(this, void 0, void 0, function () {
2159
+ var url;
2160
+ return __generator(this, function (_a) {
2161
+ switch (_a.label) {
2162
+ case 0:
2163
+ if (!data["Principal.Entity.ID"] || !data["Related.Entity.ID"] || !data["Relation.Type.ID"]) {
2164
+ throw ("Principal Entity ID, Related Entity ID, and Relation Type ID are required.");
2165
+ }
2166
+ url = "entity/" + data["Principal.Entity.ID"] + "/otherEntityID/" + data["Related.Entity.ID"] + "/relation/" + data["Relation.Type.ID"] + "/update";
2167
+ return [4 /*yield*/, api.post(url, data, Api.PrepReqParams())];
2168
+ case 1:
2169
+ data = _a.sent();
2170
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Relation + Api.ECacheKey.Id + data["Principal.Entity.ID"]);
2171
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Relation + Api.ECacheKey.Id + data["Related.Entity.ID"]);
2172
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Relation + Api.ECacheKey.RelationType + Api.ECacheKey.Id + data["Relation.Type.ID"]);
2173
+ if (data["Data.Entity.ID"]) {
2174
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Relation + Api.ECacheKey.Entity + Api.ECacheKey.Id + data["Data.Entity.ID"]);
2175
+ }
2176
+ return [2 /*return*/, data];
2177
+ }
2178
+ });
2179
+ });
2180
+ }
2181
+ EntityRelation.Update = Update;
2182
+ function GetList(api, entityId, params) {
2183
+ return __awaiter(this, void 0, void 0, function () {
2184
+ var cacheData, req;
2185
+ var _this = this;
2186
+ return __generator(this, function (_a) {
2187
+ if (!entityId) {
2188
+ throw ("Entity ID is required.");
2189
+ }
2190
+ params = __assign({ typeId: "", oneWayOnly: false, loadEntityData: false }, params);
2191
+ cacheData = api.Cache.Get(GetListCacheKey(params));
2192
+ if (cacheData) {
2193
+ return [2 /*return*/, cacheData];
2194
+ }
2195
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2196
+ var url, data, e_1;
2197
+ return __generator(this, function (_a) {
2198
+ switch (_a.label) {
2199
+ case 0:
2200
+ _a.trys.push([0, 2, , 3]);
2201
+ url = "entity/" + entityId + "/relations";
2202
+ if (params.typeId) {
2203
+ url += "/" + params.typeId;
2204
+ }
2205
+ url += "?Oneway=" + params.oneWayOnly + "&LoadInfo=" + params.loadEntityData;
2206
+ return [4 /*yield*/, api.GET(url, Api.PrepReqParams())];
2207
+ case 1:
2208
+ data = _a.sent();
2209
+ res(data.Items);
2210
+ return [3 /*break*/, 3];
2211
+ case 2:
2212
+ e_1 = _a.sent();
2213
+ rej(e_1);
2214
+ return [3 /*break*/, 3];
2215
+ case 3: return [2 /*return*/];
2216
+ }
2217
+ });
2218
+ }); });
2219
+ api.Cache.Set(GetListCacheKey(params), req);
2220
+ return [2 /*return*/, req];
2221
+ });
2222
+ });
2223
+ }
2224
+ EntityRelation.GetList = GetList;
2225
+ function GetByDataEntityId(api, entityId) {
2226
+ return __awaiter(this, void 0, void 0, function () {
2227
+ var cacheData, req;
2228
+ return __generator(this, function (_a) {
2229
+ if (!entityId) {
2230
+ throw ("Entity ID is required.");
2231
+ }
2232
+ cacheData = api.Cache.Get(GetEntityCacheKey(entityId));
2233
+ if (cacheData) {
2234
+ return [2 /*return*/, cacheData];
2235
+ }
2236
+ req = api.GET("entity/relation/" + entityId + "/dataentity", Api.PrepReqParams());
2237
+ api.Cache.Set(GetEntityCacheKey(entityId), req);
2238
+ return [2 /*return*/, req];
2239
+ });
2240
+ });
2241
+ }
2242
+ EntityRelation.GetByDataEntityId = GetByDataEntityId;
2243
+ })(EntityRelation || (EntityRelation = {}));
2244
+
2245
+ var EntitySource;
2246
+ (function (EntitySource) {
2247
+ function GetCacheKey(sourceId, sourceKey) {
2248
+ return "" + Api.ECacheKey.EntitySource + Api.ECacheKey.Id + sourceId + Api.ECacheKey.Id + sourceKey;
2249
+ }
2250
+ EntitySource.GetCacheKey = GetCacheKey;
2251
+ function Get(api, sourceId, sourceKey) {
2252
+ return __awaiter(this, void 0, void 0, function () {
2253
+ var key, cacheData, req;
2254
+ return __generator(this, function (_a) {
2255
+ if (!sourceId || !sourceKey) {
2256
+ throw ("Source ID and Source Key are required.");
2257
+ }
2258
+ key = GetCacheKey(sourceId, sourceKey);
2259
+ cacheData = api.Cache.Get(key);
2260
+ if (cacheData) {
2261
+ return [2 /*return*/, cacheData];
2262
+ }
2263
+ req = api.GET("entitysource/" + sourceId + "/" + sourceKey, Api.PrepReqParams());
2264
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
2265
+ return [2 /*return*/, req];
2266
+ });
2267
+ });
2268
+ }
2269
+ EntitySource.Get = Get;
2270
+ function GetListByKeys(api, sourceId, sourceKeys) {
2271
+ return __awaiter(this, void 0, void 0, function () {
2272
+ var reqKeys, reqs, i, sourceKey, cacheData, prom_1, _loop_1, i;
2273
+ var _this = this;
2274
+ return __generator(this, function (_a) {
2275
+ switch (_a.label) {
2276
+ case 0:
2277
+ if (!sourceId || !sourceKeys.length) {
2278
+ throw ("Source ID and Source Keys are required.");
2279
+ }
2280
+ reqKeys = [];
2281
+ reqs = [];
2282
+ for (i = 0; i < sourceKeys.length; i++) {
2283
+ sourceKey = sourceKeys[i];
2284
+ cacheData = api.Cache.Get(GetCacheKey(sourceId, sourceKey));
2285
+ if (cacheData) {
2286
+ reqs.push(cacheData);
2287
+ }
2288
+ else {
2289
+ reqKeys.push(sourceKey);
2290
+ }
2291
+ }
2292
+ if (reqKeys.length) {
2293
+ prom_1 = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2294
+ var data, e_1;
2295
+ return __generator(this, function (_a) {
2296
+ switch (_a.label) {
2297
+ case 0:
2298
+ _a.trys.push([0, 2, , 3]);
2299
+ return [4 /*yield*/, api.POST("entitysource/" + sourceId, { SourceRecordKeys: reqKeys }, Api.PrepReqParams())];
2300
+ case 1:
2301
+ data = _a.sent();
2302
+ res(data);
2303
+ return [3 /*break*/, 3];
2304
+ case 2:
2305
+ e_1 = _a.sent();
2306
+ rej(e_1);
2307
+ return [3 /*break*/, 3];
2308
+ case 3: return [2 /*return*/];
2309
+ }
2310
+ });
2311
+ }); });
2312
+ _loop_1 = function (i) {
2313
+ var req = new Promise(function (rej, res) { return __awaiter(_this, void 0, void 0, function () {
2314
+ var sources, e_2;
2315
+ return __generator(this, function (_a) {
2316
+ switch (_a.label) {
2317
+ case 0:
2318
+ _a.trys.push([0, 2, , 3]);
2319
+ return [4 /*yield*/, prom_1];
2320
+ case 1:
2321
+ sources = _a.sent();
2322
+ res(sources.find(function (s) { return s["SourceRecord.Key"] === reqKeys[i]; }));
2323
+ return [3 /*break*/, 3];
2324
+ case 2:
2325
+ e_2 = _a.sent();
2326
+ rej(e_2);
2327
+ return [3 /*break*/, 3];
2328
+ case 3: return [2 /*return*/];
2329
+ }
2330
+ });
2331
+ }); });
2332
+ reqs.push(req);
2333
+ };
2334
+ for (i = 0; i < reqKeys.length; i++) {
2335
+ _loop_1(i);
2336
+ }
2337
+ }
2338
+ return [4 /*yield*/, Promise.all(reqs)];
2339
+ case 1: return [2 /*return*/, (_a.sent()).filter(function (x) { return !!x; })];
2340
+ }
2341
+ });
2342
+ });
2343
+ }
2344
+ EntitySource.GetListByKeys = GetListByKeys;
2345
+ function GetEntityIdsBySourceKeys(api, sourceId, sourceKeys) {
2346
+ return __awaiter(this, void 0, void 0, function () {
2347
+ var result, sources, i, source, i_1, key;
2348
+ return __generator(this, function (_a) {
2349
+ switch (_a.label) {
2350
+ case 0:
2351
+ if (!sourceId || !sourceKeys.length) {
2352
+ throw ("Source ID and Source Keys are required.");
2353
+ }
2354
+ result = {};
2355
+ if (!(sourceKeys.length > 0)) return [3 /*break*/, 2];
2356
+ return [4 /*yield*/, GetListByKeys(api, sourceId, sourceKeys)];
2357
+ case 1:
2358
+ sources = _a.sent();
2359
+ for (i = 0; i < sources.length; i++) {
2360
+ source = sources[i];
2361
+ for (i_1 = 0; i_1 < sourceKeys.length; i_1++) {
2362
+ key = sourceKeys[i_1];
2363
+ if (key == source["SourceRecord.Key"]) {
2364
+ result[key] = source["Entity.ID"];
2365
+ }
2366
+ }
2367
+ }
2368
+ _a.label = 2;
2369
+ case 2: return [2 /*return*/, result];
2370
+ }
2371
+ });
2372
+ });
2373
+ }
2374
+ EntitySource.GetEntityIdsBySourceKeys = GetEntityIdsBySourceKeys;
2375
+ })(EntitySource || (EntitySource = {}));
2376
+
2377
+ var EntityTag;
2378
+ (function (EntityTag) {
2379
+ function GetCacheKey(tagId) {
2380
+ return "" + Api.ECacheKey.Tag + Api.ECacheKey.Id + tagId;
2381
+ }
2382
+ EntityTag.GetCacheKey = GetCacheKey;
2383
+ function GetListCacheKey(entityTypeId) {
2384
+ if (entityTypeId) {
2385
+ return Api.ECacheKey.Tag + Api.ECacheKey.EntityType + Api.ECacheKey.Id + entityTypeId;
2386
+ }
2387
+ return Api.ECacheKey.Tag;
2388
+ }
2389
+ EntityTag.GetListCacheKey = GetListCacheKey;
2390
+ function Get(api, tagId) {
2391
+ return __awaiter(this, void 0, void 0, function () {
2392
+ var data;
2393
+ return __generator(this, function (_a) {
2394
+ switch (_a.label) {
2395
+ case 0:
2396
+ if (!tagId) {
2397
+ throw ("Tag ID is required.");
2398
+ }
2399
+ return [4 /*yield*/, GetListByIds(api, [tagId])];
2400
+ case 1:
2401
+ data = _a.sent();
2402
+ return [2 /*return*/, data.length ? data[0] : null];
2403
+ }
2404
+ });
2405
+ });
2406
+ }
2407
+ EntityTag.Get = Get;
2408
+ function GetListByIds(api, tagIds) {
2409
+ return __awaiter(this, void 0, void 0, function () {
2410
+ var reqIds, reqs, i, tagId, cacheData, prom_1, _loop_1, i;
2411
+ var _this = this;
2412
+ return __generator(this, function (_a) {
2413
+ switch (_a.label) {
2414
+ case 0:
2415
+ if (!tagIds.length) {
2416
+ throw ("Tag Ids are empty.");
2417
+ }
2418
+ reqIds = [];
2419
+ reqs = [];
2420
+ for (i = 0; i < tagIds.length; i++) {
2421
+ tagId = tagIds[i];
2422
+ cacheData = api.Cache.Get(GetCacheKey(tagId));
2423
+ if (cacheData) {
2424
+ reqs.push(cacheData);
2425
+ }
2426
+ else {
2427
+ reqIds.push(tagId);
2428
+ }
2429
+ }
2430
+ if (reqIds.length) {
2431
+ prom_1 = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2432
+ var data, e_1;
2433
+ return __generator(this, function (_a) {
2434
+ switch (_a.label) {
2435
+ case 0:
2436
+ _a.trys.push([0, 2, , 3]);
2437
+ return [4 /*yield*/, api.POST("layers/get", { layerIds: reqIds }, Api.PrepReqParams())];
2438
+ case 1:
2439
+ data = _a.sent();
2440
+ res(data);
2441
+ return [3 /*break*/, 3];
2442
+ case 2:
2443
+ e_1 = _a.sent();
2444
+ rej(e_1);
2445
+ return [3 /*break*/, 3];
2446
+ case 3: return [2 /*return*/];
2447
+ }
2448
+ });
2449
+ }); });
2450
+ _loop_1 = function (i) {
2451
+ var req = new Promise(function (rej, res) { return __awaiter(_this, void 0, void 0, function () {
2452
+ var tags, tag, e_2;
2453
+ return __generator(this, function (_a) {
2454
+ switch (_a.label) {
2455
+ case 0:
2456
+ _a.trys.push([0, 2, , 3]);
2457
+ return [4 /*yield*/, prom_1];
2458
+ case 1:
2459
+ tags = _a.sent();
2460
+ tag = tags.find(function (t) { return t.ID === reqIds[i]; });
2461
+ res(tag);
2462
+ return [3 /*break*/, 3];
2463
+ case 2:
2464
+ e_2 = _a.sent();
2465
+ rej(e_2);
2466
+ return [3 /*break*/, 3];
2467
+ case 3: return [2 /*return*/];
2468
+ }
2469
+ });
2470
+ }); });
2471
+ reqs.push(req);
2472
+ };
2473
+ for (i = 0; i < reqIds.length; i++) {
2474
+ _loop_1(i);
2475
+ }
2476
+ }
2477
+ return [4 /*yield*/, Promise.all(reqs)];
2478
+ case 1: return [2 /*return*/, (_a.sent()).filter(function (x) { return !!x; })];
2479
+ }
2480
+ });
2481
+ });
2482
+ }
2483
+ EntityTag.GetListByIds = GetListByIds;
2484
+ function GetList(api, entityTypeId) {
2485
+ return __awaiter(this, void 0, void 0, function () {
2486
+ var cacheData, req;
2487
+ var _this = this;
2488
+ return __generator(this, function (_a) {
2489
+ cacheData = api.Cache.Get(GetListCacheKey(entityTypeId));
2490
+ if (cacheData) {
2491
+ return [2 /*return*/, cacheData];
2492
+ }
2493
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2494
+ var data, e_3;
2495
+ return __generator(this, function (_a) {
2496
+ switch (_a.label) {
2497
+ case 0:
2498
+ _a.trys.push([0, 2, , 3]);
2499
+ return [4 /*yield*/, api.GET(entityTypeId ? "entityType/" + entityTypeId + "/layers" : "layers", Api.PrepReqParams())];
2500
+ case 1:
2501
+ data = _a.sent();
2502
+ res(data.Items);
2503
+ return [3 /*break*/, 3];
2504
+ case 2:
2505
+ e_3 = _a.sent();
2506
+ rej(e_3);
2507
+ return [3 /*break*/, 3];
2508
+ case 3: return [2 /*return*/];
2509
+ }
2510
+ });
2511
+ }); });
2512
+ api.Cache.Set(GetListCacheKey(entityTypeId), req, Api.DEFAULT_CACHE_DURATION);
2513
+ return [2 /*return*/, req];
2514
+ });
2515
+ });
2516
+ }
2517
+ EntityTag.GetList = GetList;
2518
+ function Delete(api, tagId) {
2519
+ return __awaiter(this, void 0, void 0, function () {
2520
+ return __generator(this, function (_a) {
2521
+ switch (_a.label) {
2522
+ case 0:
2523
+ if (!tagId) {
2524
+ throw ("Tag ID is required.");
2525
+ }
2526
+ return [4 /*yield*/, api.DELETE("layer/" + tagId, Api.PrepReqParams())];
2527
+ case 1:
2528
+ _a.sent();
2529
+ api.Cache.Remove(GetCacheKey(tagId));
2530
+ api.Cache.RemoveByStartsWith(GetListCacheKey());
2531
+ return [2 /*return*/];
2532
+ }
2533
+ });
2534
+ });
2535
+ }
2536
+ EntityTag.Delete = Delete;
2537
+ function Update(api, data) {
2538
+ return __awaiter(this, void 0, void 0, function () {
2539
+ var url;
2540
+ return __generator(this, function (_a) {
2541
+ switch (_a.label) {
2542
+ case 0:
2543
+ if (!(data === null || data === void 0 ? void 0 : data.ID)) {
2544
+ throw ("Tag ID is required.");
2545
+ }
2546
+ url = data.ID ? "layer/" + data.ID : "layer";
2547
+ return [4 /*yield*/, api.post(url, data, Api.PrepReqParams())];
2548
+ case 1:
2549
+ data = _a.sent();
2550
+ api.Cache.Remove(GetCacheKey(data.ID));
2551
+ api.Cache.RemoveByStartsWith(GetListCacheKey());
2552
+ return [2 /*return*/, data];
2553
+ }
2554
+ });
2555
+ });
2556
+ }
2557
+ EntityTag.Update = Update;
2558
+ })(EntityTag || (EntityTag = {}));
2559
+
2560
+ var EntityType;
2561
+ (function (EntityType) {
2562
+ function GetCacheKey(typeId) {
2563
+ return "" + Api.ECacheKey.EntityType + Api.ECacheKey.Id + typeId;
2564
+ }
2565
+ EntityType.GetCacheKey = GetCacheKey;
2566
+ function GetListCacheKey() {
2567
+ return Api.ECacheKey.EntityType;
2568
+ }
2569
+ EntityType.GetListCacheKey = GetListCacheKey;
2570
+ var EAttributeType;
2571
+ (function (EAttributeType) {
2572
+ EAttributeType["String"] = "String";
2573
+ EAttributeType["Double"] = "Double";
2574
+ EAttributeType["Integer"] = "Integer";
2575
+ EAttributeType["Datetime"] = "Datetime";
2576
+ EAttributeType["Structure"] = "Structure";
2577
+ EAttributeType["Geometry"] = "Geometry";
2578
+ })(EAttributeType = EntityType.EAttributeType || (EntityType.EAttributeType = {}));
2579
+ function Get(api, typeId) {
2580
+ return __awaiter(this, void 0, void 0, function () {
2581
+ var key, cacheData, req;
2582
+ return __generator(this, function (_a) {
2583
+ if (!typeId) {
2584
+ throw ("Type ID is required.");
2585
+ }
2586
+ key = GetCacheKey(typeId);
2587
+ cacheData = api.Cache.Get(key);
2588
+ if (cacheData) {
2589
+ return [2 /*return*/, cacheData];
2590
+ }
2591
+ req = api.GET("entitytype/" + typeId, Api.PrepReqParams());
2592
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
2593
+ return [2 /*return*/, req];
2594
+ });
2595
+ });
2596
+ }
2597
+ EntityType.Get = Get;
2598
+ function Delete(api, typeId) {
2599
+ return __awaiter(this, void 0, void 0, function () {
2600
+ return __generator(this, function (_a) {
2601
+ switch (_a.label) {
2602
+ case 0:
2603
+ if (!typeId) {
2604
+ throw ("Type ID is required.");
2605
+ }
2606
+ return [4 /*yield*/, api.DELETE("entitytype/" + typeId, Api.PrepReqParams())];
2607
+ case 1:
2608
+ _a.sent();
2609
+ api.Cache.Remove(GetCacheKey(typeId));
2610
+ api.Cache.Remove(GetListCacheKey());
2611
+ return [2 /*return*/];
2612
+ }
2613
+ });
2614
+ });
2615
+ }
2616
+ EntityType.Delete = Delete;
2617
+ function GetList(api) {
2618
+ return __awaiter(this, void 0, void 0, function () {
2619
+ var cacheData, req;
2620
+ var _this = this;
2621
+ return __generator(this, function (_a) {
2622
+ cacheData = api.Cache.Get(GetListCacheKey());
2623
+ if (cacheData) {
2624
+ return [2 /*return*/, cacheData];
2625
+ }
2626
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
2627
+ var data, e_1;
2628
+ return __generator(this, function (_a) {
2629
+ switch (_a.label) {
2630
+ case 0:
2631
+ _a.trys.push([0, 2, , 3]);
2632
+ return [4 /*yield*/, api.GET("entitytypes", Api.PrepReqParams())];
2633
+ case 1:
2634
+ data = _a.sent();
2635
+ res(data.Items);
2636
+ return [3 /*break*/, 3];
2637
+ case 2:
2638
+ e_1 = _a.sent();
2639
+ rej(e_1);
2640
+ return [3 /*break*/, 3];
2641
+ case 3: return [2 /*return*/];
2642
+ }
2643
+ });
2644
+ }); });
2645
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
2646
+ return [2 /*return*/, req];
2647
+ });
2648
+ });
2649
+ }
2650
+ EntityType.GetList = GetList;
2651
+ function Update(api, data) {
2652
+ return __awaiter(this, void 0, void 0, function () {
2653
+ return __generator(this, function (_a) {
2654
+ switch (_a.label) {
2655
+ case 0:
2656
+ if (!data) {
2657
+ data = {};
2658
+ }
2659
+ if (!data.ID) {
2660
+ data.ID = ObjectUtils.UId();
2661
+ }
2662
+ if (!data.Name) {
2663
+ data.Name = data.ID;
2664
+ }
2665
+ return [4 /*yield*/, api.POST("entitytype", data, Api.PrepReqParams())];
2666
+ case 1:
2667
+ data = _a.sent();
2668
+ api.Cache.Remove(GetCacheKey(data.ID));
2669
+ api.Cache.Remove(GetListCacheKey());
2670
+ return [2 /*return*/, data];
2671
+ }
2672
+ });
2673
+ });
2674
+ }
2675
+ EntityType.Update = Update;
2676
+ })(EntityType || (EntityType = {}));
2677
+
2678
+ var Cell = /** @class */ (function () {
2679
+ function Cell() {
2680
+ this.Fetched = false;
2681
+ this.IsFetched = null;
2682
+ this.FetchPageIndex = 0;
2683
+ this.Boundaries = null;
2684
+ }
2685
+ Cell.prototype.GetBounds = function () {
2686
+ // Entity data works in -180 to 180 range.
2687
+ function prepareRangeForBounds(range) {
2688
+ if (range > 180) {
2689
+ return range - 360;
2690
+ }
2691
+ return range;
2692
+ }
2693
+ // Add minor decimal as API crashes when giving it whole numbers.
2694
+ var maxLon = prepareRangeForBounds(this.Boundaries.maxLongitude) + 0.00001;
2695
+ var minLon = prepareRangeForBounds(this.Boundaries.minLongitude) - 0.00001;
2696
+ var maxLat = prepareRangeForBounds(this.Boundaries.maxLatitude) + 0.00001;
2697
+ var minLat = prepareRangeForBounds(this.Boundaries.minLatitude) - 0.00001;
2698
+ return {
2699
+ east: maxLon,
2700
+ north: maxLat,
2701
+ south: minLat,
2702
+ west: minLon
2703
+ };
2704
+ };
2705
+ return Cell;
2706
+ }());
2707
+ function floorValueToCellSize(size, value) {
2708
+ return Math.floor(value / size) * size;
2709
+ }
2710
+ function getCellSizeFromHeight(height) {
2711
+ if (height < 1000) {
2712
+ return 0.01;
2713
+ }
2714
+ if (height < 5000) {
2715
+ return 0.025;
2716
+ }
2717
+ else if (height < 10000) {
2718
+ return 0.05;
2719
+ }
2720
+ else if (height < 30000) {
2721
+ return 0.1;
2722
+ }
2723
+ else if (height < 70000) {
2724
+ return 0.2;
2725
+ }
2726
+ else if (height < 100000) {
2727
+ return 0.3;
2728
+ }
2729
+ else if (height < 150000) {
2730
+ return 0.4;
2731
+ }
2732
+ else if (height < 200000) {
2733
+ return 0.5;
2734
+ }
2735
+ else if (height < 300000) {
2736
+ return 0.6;
2737
+ }
2738
+ else if (height < 500000) {
2739
+ return 1;
2740
+ }
2741
+ return 1.5;
2742
+ }
2743
+ function getCell(cells, cellSize, lon, maxLon, lat, maxLat) {
2744
+ var id = cellSize + "_" + lon + "_" + maxLon + "_" + lat + "_" + maxLat;
2745
+ return cells[id];
2746
+ }
2747
+ function isCellFetched(cell) {
2748
+ if (cell.Fetched) {
2749
+ return true;
2750
+ }
2751
+ // TODO: If all cells of the size smaller are fetched then this is fetched.
2752
+ // TODO: If this is a cell within a larger cell that is fetched then this is fetched.
2753
+ return false;
2754
+ }
2755
+ function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
2756
+ var id = cellSize + "_" + lon + "_" + maxLon + "_" + lat + "_" + maxLat;
2757
+ var cell = getCell(cells, cellSize, lon, maxLon, lat, maxLat);
2758
+ if (!cell) {
2759
+ cell = cells[id] = new Cell();
2760
+ cell.Boundaries = {
2761
+ minLatitude: lat,
2762
+ maxLatitude: maxLat,
2763
+ minLongitude: lon,
2764
+ maxLongitude: maxLon
2765
+ };
2766
+ cell.IsFetched = function () { return isCellFetched(cell); };
2767
+ }
2768
+ return cell;
2769
+ }
2770
+ var EntityGlobe;
2771
+ (function (EntityGlobe) {
2772
+ var Grid = /** @class */ (function () {
2773
+ function Grid() {
2774
+ this.cells = {};
2775
+ }
2776
+ Grid.prototype.GetCellsForView = function (viewRect) {
2777
+ var cells = [];
2778
+ var minLat = viewRect.south;
2779
+ var minLon = viewRect.west;
2780
+ var maxLat = viewRect.north;
2781
+ var maxLon = viewRect.east;
2782
+ var MAX_CELLS = 150;
2783
+ var cellDegreeSize = getCellSizeFromHeight(viewRect.alt);
2784
+ var curMinLon = floorValueToCellSize(cellDegreeSize, minLon);
2785
+ var curMinLat = floorValueToCellSize(cellDegreeSize, minLat);
2786
+ var width = (maxLon - curMinLon) / cellDegreeSize;
2787
+ var height = (maxLat - curMinLat) / cellDegreeSize;
2788
+ for (var x = 0; x < width; x++) {
2789
+ for (var y = 0; y < height; y++) {
2790
+ var lon = x * cellDegreeSize + curMinLon;
2791
+ var lat = y * cellDegreeSize + curMinLat;
2792
+ var cell = getOrCreateCell(this.cells, cellDegreeSize, lon, lon + cellDegreeSize, lat, lat + cellDegreeSize);
2793
+ cells.push(cell);
2794
+ if (cells.length > MAX_CELLS) {
2795
+ break;
2796
+ }
2797
+ }
2798
+ }
2799
+ return cells;
2800
+ };
2801
+ return Grid;
2802
+ }());
2803
+ EntityGlobe.Grid = Grid;
2804
+ })(EntityGlobe || (EntityGlobe = {}));
2805
+
2806
+ var MAX_AREA_IN_DEGREES = 90;
2807
+ var MAX_RETRY_ATTEMPTS = 1;
2808
+ var RETRY_DELAY_INCREMENT = 500;
2809
+ var REQUEST_PAGE_DELAY = 50;
2810
+ var regMenuItemGetter = /** @class */ (function () {
2811
+ function regMenuItemGetter(tagIds, minHeight, maxHeight) {
2812
+ this.TagIds = tagIds;
2813
+ this.MinHeight = minHeight;
2814
+ this.MaxHeight = maxHeight;
2815
+ }
2816
+ return regMenuItemGetter;
2817
+ }());
2818
+ function delay(milliseconds) {
2819
+ return __awaiter(this, void 0, void 0, function () {
2820
+ return __generator(this, function (_a) {
2821
+ return [2 /*return*/, new Promise(function (res) {
2822
+ setTimeout(function () {
2823
+ res();
2824
+ }, milliseconds);
2825
+ })];
2826
+ });
2827
+ });
2828
+ }
2829
+ var EntityFilterGetter;
2830
+ (function (EntityFilterGetter) {
2831
+ var EStatus;
2832
+ (function (EStatus) {
2833
+ EStatus["Scanning"] = "SCANNING";
2834
+ EStatus["Loading"] = "LOADING";
2835
+ })(EStatus = EntityFilterGetter.EStatus || (EntityFilterGetter.EStatus = {}));
2836
+ var Getter = /** @class */ (function () {
2837
+ function Getter(api, viewPort, typeId, batchSize, attrFilter) {
2838
+ this.onUpdate = null;
2839
+ this.LastStateUpdates = {};
2840
+ this.onStateUpdate = null;
2841
+ this.viewPortChangeRemoval = null;
2842
+ this.cells = null;
2843
+ this.registeredItems = {};
2844
+ this.getterLoopId = 0;
2845
+ this.tagIds = null;
2846
+ this.minHeight = 0;
2847
+ this.maxHeight = 100000;
2848
+ this.viewRect = null;
2849
+ this.viewCenter = null;
2850
+ this.api = api;
2851
+ this.typeId = typeId;
2852
+ this.batchSize = batchSize;
2853
+ this.viewPort = viewPort;
2854
+ this.attrFilter = attrFilter;
2855
+ }
2856
+ Object.defineProperty(Getter.prototype, "OnUpdate", {
2857
+ get: function () {
2858
+ if (!this.onUpdate) {
2859
+ this.onUpdate = new BruceEvent();
2860
+ }
2861
+ return this.onUpdate;
2862
+ },
2863
+ enumerable: false,
2864
+ configurable: true
2865
+ });
2866
+ Object.defineProperty(Getter.prototype, "OnStateUpdate", {
2867
+ get: function () {
2868
+ if (!this.onStateUpdate) {
2869
+ this.onStateUpdate = new BruceEvent();
2870
+ }
2871
+ return this.onStateUpdate;
2872
+ },
2873
+ enumerable: false,
2874
+ configurable: true
2875
+ });
2876
+ Getter.prototype.viewAreaSub = function () {
2877
+ var _this = this;
2878
+ this.viewAreaDispose();
2879
+ this.viewPortChangeRemoval = this.viewPort.Updated().Subscribe(function () {
2880
+ _this.updateBounds();
2881
+ _this.startGetterLoop();
2882
+ });
2883
+ };
2884
+ Getter.prototype.viewAreaDispose = function () {
2885
+ var _a;
2886
+ (_a = this.viewPortChangeRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
2887
+ };
2888
+ Getter.prototype.GetMenuItems = function () {
2889
+ return Object.keys(this.registeredItems);
2890
+ };
2891
+ Getter.prototype.IncludeMenuItem = function (menuItemId, layerIds, minHeight, maxHeight) {
2892
+ this.registeredItems[menuItemId] = new regMenuItemGetter(layerIds, minHeight, maxHeight);
2893
+ this.updateState();
2894
+ };
2895
+ Getter.prototype.ExcludeMenuItem = function (menuItemId) {
2896
+ this.registeredItems[menuItemId] = null;
2897
+ delete this.registeredItems[menuItemId];
2898
+ this.updateState();
2899
+ };
2900
+ Getter.prototype.updateBounds = function () {
2901
+ var viewRect = this.viewPort.GetBounds();
2902
+ var poi = this.viewPort.GetTarget();
2903
+ if (viewRect && poi) {
2904
+ if (Math.abs(viewRect.west - viewRect.east) > MAX_AREA_IN_DEGREES) {
2905
+ return;
2906
+ }
2907
+ if (Math.abs(viewRect.south - viewRect.north) > MAX_AREA_IN_DEGREES) {
2908
+ return;
2909
+ }
2910
+ this.viewRect = viewRect;
2911
+ this.viewCenter = poi;
2912
+ }
2913
+ };
2914
+ Getter.prototype.updateState = function () {
2915
+ var tagIds = [];
2916
+ var menuItemIds = this.GetMenuItems();
2917
+ var minHeight = null;
2918
+ var maxHeight = null;
2919
+ for (var i = 0; i < menuItemIds.length; i++) {
2920
+ var menuItem = this.registeredItems[menuItemIds[i]];
2921
+ if (menuItem) {
2922
+ if (maxHeight == null || maxHeight < menuItem.MaxHeight) {
2923
+ maxHeight = menuItem.MaxHeight;
2924
+ }
2925
+ if (minHeight == null || minHeight > menuItem.MinHeight) {
2926
+ minHeight = menuItem.MinHeight;
2927
+ }
2928
+ var itemLayerIds = menuItem.TagIds;
2929
+ if (itemLayerIds) {
2930
+ for (var j = 0; j < itemLayerIds.length; j++) {
2931
+ var itemLayerId = itemLayerIds[j];
2932
+ if (!tagIds.includes(itemLayerId)) {
2933
+ tagIds.push(itemLayerId);
2934
+ }
2935
+ }
2936
+ }
2937
+ }
2938
+ }
2939
+ if (menuItemIds.length > 0) {
2940
+ // Reset cells so none are marked as fetched.
2941
+ this.cells = new EntityGlobe.Grid();
2942
+ this.tagIds = tagIds;
2943
+ this.minHeight = minHeight;
2944
+ this.maxHeight = maxHeight;
2945
+ this.updateBounds();
2946
+ this.startGetterLoop();
2947
+ this.viewAreaSub();
2948
+ }
2949
+ else {
2950
+ this.getterLoopId = -1;
2951
+ this.viewAreaDispose();
2952
+ }
2953
+ };
2954
+ Getter.prototype.postStatus = function (status) {
2955
+ var _a;
2956
+ this.LastStateUpdates[status.msg] = status;
2957
+ (_a = this.onStateUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(status);
2958
+ };
2959
+ Getter.prototype.startGetterLoop = function () {
2960
+ var _this = this;
2961
+ // Increase id so that existing loops stop.
2962
+ this.getterLoopId += 1;
2963
+ var loopId = this.getterLoopId;
2964
+ new Promise(function () { return __awaiter(_this, void 0, void 0, function () {
2965
+ var MIN_HEIGHT, MAX_HEIGHT, PAGE_SIZE, retryAttempts, retryDelay, prevFirstId, prevLastId, alt, cells, curCellIndex, postedScanning, postedLoading, curCell, page, first, last, e_1;
2966
+ var _a, _b, _c, _d, _e;
2967
+ return __generator(this, function (_f) {
2968
+ switch (_f.label) {
2969
+ case 0:
2970
+ // Minor delay to stop 50 menu items enabling doing their first request all together.
2971
+ // This gives it time to recognize only 1 request is needed.
2972
+ // Would be better to not use this delay but we're on a clock.
2973
+ return [4 /*yield*/, delay(100)];
2974
+ case 1:
2975
+ // Minor delay to stop 50 menu items enabling doing their first request all together.
2976
+ // This gives it time to recognize only 1 request is needed.
2977
+ // Would be better to not use this delay but we're on a clock.
2978
+ _f.sent();
2979
+ MIN_HEIGHT = this.minHeight;
2980
+ MAX_HEIGHT = this.maxHeight;
2981
+ PAGE_SIZE = this.batchSize;
2982
+ retryAttempts = MAX_RETRY_ATTEMPTS;
2983
+ retryDelay = 0;
2984
+ prevFirstId = "";
2985
+ prevLastId = "";
2986
+ _f.label = 2;
2987
+ case 2:
2988
+ if (!((!this.viewCenter || !this.viewRect) && this.getterLoopId == loopId)) return [3 /*break*/, 4];
2989
+ return [4 /*yield*/, delay(RETRY_DELAY_INCREMENT)];
2990
+ case 3:
2991
+ _f.sent();
2992
+ return [3 /*break*/, 2];
2993
+ case 4:
2994
+ if (this.getterLoopId != loopId) {
2995
+ return [2 /*return*/];
2996
+ }
2997
+ alt = this.viewRect.alt;
2998
+ if (alt > MAX_HEIGHT || (alt < MIN_HEIGHT && MIN_HEIGHT > 0)) {
2999
+ return [2 /*return*/];
3000
+ }
3001
+ cells = this.cells.GetCellsForView(this.viewRect);
3002
+ curCellIndex = cells.length > 0 ? 0 : null;
3003
+ postedScanning = false;
3004
+ postedLoading = false;
3005
+ _f.label = 5;
3006
+ case 5:
3007
+ if (!(retryAttempts > 0 && curCellIndex != null)) return [3 /*break*/, 13];
3008
+ if (this.getterLoopId != loopId) {
3009
+ return [3 /*break*/, 13];
3010
+ }
3011
+ if (!(retryDelay > 0)) return [3 /*break*/, 7];
3012
+ return [4 /*yield*/, delay(retryDelay)];
3013
+ case 6:
3014
+ _f.sent();
3015
+ _f.label = 7;
3016
+ case 7:
3017
+ if (!postedScanning) {
3018
+ this.postStatus({ msg: EStatus.Scanning, revoking: false });
3019
+ postedScanning = true;
3020
+ }
3021
+ curCell = cells[curCellIndex];
3022
+ if (curCell.IsFetched()) {
3023
+ curCellIndex += 1;
3024
+ if (!cells[curCellIndex]) {
3025
+ curCellIndex = null;
3026
+ }
3027
+ return [3 /*break*/, 5];
3028
+ }
3029
+ _f.label = 8;
3030
+ case 8:
3031
+ _f.trys.push([8, 10, , 11]);
3032
+ return [4 /*yield*/, Entity.Filter.V1.GetList(this.api, {
3033
+ pageSize: PAGE_SIZE,
3034
+ pageIndex: curCell.FetchPageIndex,
3035
+ entityTypeId: this.typeId,
3036
+ layerIds: this.tagIds,
3037
+ bounds: curCell.GetBounds(),
3038
+ sortOrder: Api.ESortOrder.Asc,
3039
+ entityTypeConditions: this.attrFilter
3040
+ })];
3041
+ case 9:
3042
+ page = _f.sent();
3043
+ if (this.getterLoopId != loopId) {
3044
+ return [3 /*break*/, 13];
3045
+ }
3046
+ if (page) {
3047
+ (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(page);
3048
+ }
3049
+ if (!postedLoading) {
3050
+ this.postStatus({ msg: EStatus.Loading, revoking: false });
3051
+ postedLoading = true;
3052
+ }
3053
+ if (page.length <= 0) {
3054
+ curCell.Fetched = true; // Only mark as fetched when ALL pages are done.
3055
+ return [3 /*break*/, 5];
3056
+ }
3057
+ // Checking to make sure it's not just the same batch over and over again.
3058
+ if (page.length > 0) {
3059
+ first = (_c = (_b = page[0]) === null || _b === void 0 ? void 0 : _b.Bruce) === null || _c === void 0 ? void 0 : _c.ID;
3060
+ last = (_e = (_d = page[page.length - 1]) === null || _d === void 0 ? void 0 : _d.Bruce) === null || _e === void 0 ? void 0 : _e.ID;
3061
+ if (prevFirstId == first && prevLastId == last) {
3062
+ return [3 /*break*/, 13];
3063
+ }
3064
+ else {
3065
+ prevFirstId = first;
3066
+ prevLastId = last;
3067
+ }
3068
+ }
3069
+ curCell.FetchPageIndex++;
3070
+ // Request passed so let's assume it was server hiccup and refresh counts.
3071
+ retryAttempts = MAX_RETRY_ATTEMPTS;
3072
+ retryDelay = 0;
3073
+ return [3 /*break*/, 11];
3074
+ case 10:
3075
+ e_1 = _f.sent();
3076
+ console.log(e_1);
3077
+ // Request failed so let's add a delay and try again soon.
3078
+ retryDelay += RETRY_DELAY_INCREMENT;
3079
+ retryAttempts -= 1;
3080
+ return [3 /*break*/, 11];
3081
+ case 11: return [4 /*yield*/, delay(REQUEST_PAGE_DELAY)];
3082
+ case 12:
3083
+ _f.sent();
3084
+ return [3 /*break*/, 5];
3085
+ case 13:
3086
+ if (postedLoading) {
3087
+ this.postStatus({ msg: EStatus.Loading, revoking: true });
3088
+ }
3089
+ if (postedScanning) {
3090
+ this.postStatus({ msg: EStatus.Scanning, revoking: true });
3091
+ }
3092
+ return [2 /*return*/];
3093
+ }
3094
+ });
3095
+ }); });
3096
+ };
3097
+ return Getter;
3098
+ }());
3099
+ EntityFilterGetter.Getter = Getter;
3100
+ })(EntityFilterGetter || (EntityFilterGetter = {}));
3101
+
3102
+ var MAX_AREA_IN_DEGREES$1 = 90;
3103
+ var GETTER_DELAY = 50;
3104
+ var EntityLoadedGetter = /** @class */ (function () {
3105
+ function EntityLoadedGetter(entities, viewPort, batchSize) {
3106
+ var _this = this;
3107
+ this.viewPortRemoval = null;
3108
+ this.viewRect = null;
3109
+ this.viewCenter = null;
3110
+ this.onUpdate = null;
3111
+ this.entities = entities;
3112
+ this.viewPort = viewPort;
3113
+ this.batchSize = batchSize;
3114
+ this.viewPortRemoval = this.viewPort.Updated().Subscribe(function () {
3115
+ _this.updateBounds();
3116
+ _this.startGetterLoop();
3117
+ });
3118
+ }
3119
+ Object.defineProperty(EntityLoadedGetter.prototype, "OnUpdate", {
3120
+ get: function () {
3121
+ if (!this.onUpdate) {
3122
+ this.onUpdate = new BruceEvent();
3123
+ }
3124
+ return this.onUpdate;
3125
+ },
3126
+ enumerable: false,
3127
+ configurable: true
3128
+ });
3129
+ EntityLoadedGetter.prototype.Dispose = function () {
3130
+ var _a;
3131
+ (_a = this.viewPortRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
3132
+ };
3133
+ EntityLoadedGetter.prototype.updateBounds = function () {
3134
+ var viewRect = this.viewPort.GetBounds();
3135
+ var poi = this.viewPort.GetTarget();
3136
+ if (viewRect && poi) {
3137
+ if (Math.abs(viewRect.west - viewRect.east) > MAX_AREA_IN_DEGREES$1) {
3138
+ return;
3139
+ }
3140
+ if (Math.abs(viewRect.south - viewRect.north) > MAX_AREA_IN_DEGREES$1) {
3141
+ return;
3142
+ }
3143
+ this.viewRect = viewRect;
3144
+ this.viewCenter = poi;
3145
+ }
3146
+ };
3147
+ EntityLoadedGetter.prototype.startGetterLoop = function () {
3148
+ var _this = this;
3149
+ clearInterval(this.getterInterval);
3150
+ if (!this.viewRect || !this.viewCenter) {
3151
+ return;
3152
+ }
3153
+ var index = 0;
3154
+ this.getterInterval = setInterval(function () {
3155
+ _this.processBatch(_this.entities.slice(index, index + _this.batchSize));
3156
+ index += _this.batchSize;
3157
+ if (index >= _this.entities.length) {
3158
+ clearInterval(_this.getterInterval);
3159
+ }
3160
+ }, GETTER_DELAY);
3161
+ };
3162
+ EntityLoadedGetter.prototype.processBatch = function (batch) {
3163
+ var _a;
3164
+ if (batch.length > 0) {
3165
+ (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(batch);
3166
+ }
3167
+ };
3168
+ return EntityLoadedGetter;
3169
+ }());
3170
+
3171
+ var ClientFile;
3172
+ (function (ClientFile) {
3173
+ function GetCacheKey(fileId) {
3174
+ return "" + Api.ECacheKey.ClientFile + Api.ECacheKey.Id + fileId;
3175
+ }
3176
+ ClientFile.GetCacheKey = GetCacheKey;
3177
+ function Get(api, fileId) {
3178
+ return __awaiter(this, void 0, void 0, function () {
3179
+ var key, cacheData, req;
3180
+ return __generator(this, function (_a) {
3181
+ if (!fileId) {
3182
+ throw ("File ID is required.");
3183
+ }
3184
+ key = GetCacheKey(fileId);
3185
+ cacheData = api.Cache.Get(key);
3186
+ if (cacheData) {
3187
+ return [2 /*return*/, cacheData];
3188
+ }
3189
+ req = api.GET("file/" + fileId + "/details", Api.PrepReqParams());
3190
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
3191
+ return [2 /*return*/, req];
3192
+ });
3193
+ });
3194
+ }
3195
+ ClientFile.Get = Get;
3196
+ function Delete(api, fileIds) {
3197
+ return __awaiter(this, void 0, void 0, function () {
3198
+ var data, i, key;
3199
+ return __generator(this, function (_a) {
3200
+ switch (_a.label) {
3201
+ case 0:
3202
+ if (!fileIds.length) {
3203
+ throw ("File IDs are required.");
3204
+ }
3205
+ data = {
3206
+ Items: fileIds
3207
+ };
3208
+ return [4 /*yield*/, api.POST("deleteFiles", data, Api.PrepReqParams())];
3209
+ case 1:
3210
+ _a.sent();
3211
+ for (i = 0; i < fileIds.length; i++) {
3212
+ key = GetCacheKey(fileIds[i]);
3213
+ api.Cache.Remove(key);
3214
+ }
3215
+ return [2 /*return*/];
3216
+ }
3217
+ });
3218
+ });
3219
+ }
3220
+ ClientFile.Delete = Delete;
3221
+ function Upload(api, file, onProgress) {
3222
+ return __awaiter(this, void 0, void 0, function () {
3223
+ return __generator(this, function (_a) {
3224
+ if (!file) {
3225
+ throw ("File is required.");
3226
+ }
3227
+ return [2 /*return*/, api.UPLOAD("file/uploadNew", file, { onProgress: onProgress })];
3228
+ });
3229
+ });
3230
+ }
3231
+ ClientFile.Upload = Upload;
3232
+ var Filter;
3233
+ (function (Filter) {
3234
+ var V1;
3235
+ (function (V1) {
3236
+ var EColumn;
3237
+ (function (EColumn) {
3238
+ EColumn["ID"] = "id";
3239
+ EColumn["Name"] = "name";
3240
+ EColumn["DateTime"] = "datetime";
3241
+ EColumn["MIMEType"] = "mimeType";
3242
+ EColumn["Size"] = "size";
3243
+ EColumn["User"] = "user";
3244
+ EColumn["Extension"] = "extension";
3245
+ })(EColumn = V1.EColumn || (V1.EColumn = {}));
3246
+ var ESortOrder;
3247
+ (function (ESortOrder) {
3248
+ ESortOrder["ASC"] = "asc";
3249
+ ESortOrder["DEC"] = "desc";
3250
+ })(ESortOrder = V1.ESortOrder || (V1.ESortOrder = {}));
3251
+ var ERowOperator;
3252
+ (function (ERowOperator) {
3253
+ ERowOperator["AND"] = "AND";
3254
+ ERowOperator["OR"] = "OR";
3255
+ })(ERowOperator = V1.ERowOperator || (V1.ERowOperator = {}));
3256
+ function GetList(api, filter) {
3257
+ return __awaiter(this, void 0, void 0, function () {
3258
+ var data;
3259
+ return __generator(this, function (_a) {
3260
+ switch (_a.label) {
3261
+ case 0: return [4 /*yield*/, api.POST("files/filtered", filter, Api.PrepReqParams())];
3262
+ case 1:
3263
+ data = _a.sent();
3264
+ return [2 /*return*/, data.Items];
3265
+ }
3266
+ });
3267
+ });
3268
+ }
3269
+ V1.GetList = GetList;
3270
+ })(V1 = Filter.V1 || (Filter.V1 = {}));
3271
+ // TODO: Helpers for constructing the filter.
3272
+ })(Filter = ClientFile.Filter || (ClientFile.Filter = {}));
3273
+ })(ClientFile || (ClientFile = {}));
3274
+
3275
+ var ProgramKey;
3276
+ (function (ProgramKey) {
3277
+ function GetCacheKey(programId) {
3278
+ return Api.ECacheKey.ProgramKey + Api.ECacheKey.Id + programId;
3279
+ }
3280
+ ProgramKey.GetCacheKey = GetCacheKey;
3281
+ function GetListCacheKey() {
3282
+ return Api.ECacheKey.ProgramKey;
3283
+ }
3284
+ ProgramKey.GetListCacheKey = GetListCacheKey;
3285
+ var EProgramId;
3286
+ (function (EProgramId) {
3287
+ EProgramId["CesiumIon"] = "CesiumIon";
3288
+ EProgramId["BingMaps"] = "BingMaps";
3289
+ EProgramId["Mapbox"] = "Mapbox";
3290
+ })(EProgramId = ProgramKey.EProgramId || (ProgramKey.EProgramId = {}));
3291
+ function Get(api, programId) {
3292
+ return __awaiter(this, void 0, void 0, function () {
3293
+ var key, cacheData, req;
3294
+ return __generator(this, function (_a) {
3295
+ if (!programId) {
3296
+ throw ("Program ID is required.");
3297
+ }
3298
+ key = GetCacheKey(programId);
3299
+ cacheData = api.Cache.Get(key);
3300
+ if (cacheData) {
3301
+ return [2 /*return*/, cacheData];
3302
+ }
3303
+ req = api.GET("programkey/" + programId, Api.PrepReqParams());
3304
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
3305
+ return [2 /*return*/, req];
3306
+ });
3307
+ });
3308
+ }
3309
+ ProgramKey.Get = Get;
3310
+ function GetList(api) {
3311
+ return __awaiter(this, void 0, void 0, function () {
3312
+ var cacheData, req;
3313
+ var _this = this;
3314
+ return __generator(this, function (_a) {
3315
+ cacheData = api.Cache.Get(GetListCacheKey());
3316
+ if (cacheData) {
3317
+ return [2 /*return*/, cacheData];
3318
+ }
3319
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
3320
+ var data, e_1;
3321
+ return __generator(this, function (_a) {
3322
+ switch (_a.label) {
3323
+ case 0:
3324
+ _a.trys.push([0, 2, , 3]);
3325
+ return [4 /*yield*/, api.GET("programkeys", Api.PrepReqParams())];
3326
+ case 1:
3327
+ data = _a.sent();
3328
+ res(data.Items);
3329
+ return [3 /*break*/, 3];
3330
+ case 2:
3331
+ e_1 = _a.sent();
3332
+ rej(e_1);
3333
+ return [3 /*break*/, 3];
3334
+ case 3: return [2 /*return*/];
3335
+ }
3336
+ });
3337
+ }); });
3338
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
3339
+ return [2 /*return*/, req];
3340
+ });
3341
+ });
3342
+ }
3343
+ ProgramKey.GetList = GetList;
3344
+ function Delete(api, programId) {
3345
+ return __awaiter(this, void 0, void 0, function () {
3346
+ return __generator(this, function (_a) {
3347
+ switch (_a.label) {
3348
+ case 0:
3349
+ if (!programId) {
3350
+ throw ("Program ID is required.");
3351
+ }
3352
+ return [4 /*yield*/, api.DELETE("programkey/" + programId, Api.PrepReqParams())];
3353
+ case 1:
3354
+ _a.sent();
3355
+ api.Cache.Remove(GetCacheKey(programId));
3356
+ api.Cache.Remove(GetListCacheKey());
3357
+ return [2 /*return*/];
3358
+ }
3359
+ });
3360
+ });
3361
+ }
3362
+ ProgramKey.Delete = Delete;
3363
+ function Update(api, data) {
3364
+ return __awaiter(this, void 0, void 0, function () {
3365
+ return __generator(this, function (_a) {
3366
+ switch (_a.label) {
3367
+ case 0:
3368
+ if (!(data === null || data === void 0 ? void 0 : data.ProgramId)) {
3369
+ throw ("Program ID is required.");
3370
+ }
3371
+ return [4 /*yield*/, api.post("programkey", data, Api.PrepReqParams())];
3372
+ case 1:
3373
+ data = _a.sent();
3374
+ api.Cache.Remove(GetCacheKey(data.ProgramId));
3375
+ api.Cache.Remove(GetListCacheKey());
3376
+ return [2 /*return*/, data];
3377
+ }
3378
+ });
3379
+ });
3380
+ }
3381
+ ProgramKey.Update = Update;
3382
+ })(ProgramKey || (ProgramKey = {}));
3383
+
3384
+ var MenuItemZoomControl;
3385
+ (function (MenuItemZoomControl) {
3386
+ var EDisplayType;
3387
+ (function (EDisplayType) {
3388
+ EDisplayType["Hidden"] = "hidden";
3389
+ EDisplayType["Point"] = "point";
3390
+ EDisplayType["Geometry"] = "geometry";
3391
+ EDisplayType["Model3D"] = "3d";
3392
+ })(EDisplayType = MenuItemZoomControl.EDisplayType || (MenuItemZoomControl.EDisplayType = {}));
3393
+ })(MenuItemZoomControl || (MenuItemZoomControl = {}));
3394
+
3395
+ var Tileset;
3396
+ (function (Tileset) {
3397
+ function GetCacheKey(tilesetId, loadFiles) {
3398
+ return "" + Api.ECacheKey.Tileset + Api.ECacheKey.Id + tilesetId + Api.ECacheKey.Id + loadFiles;
3399
+ }
3400
+ Tileset.GetCacheKey = GetCacheKey;
3401
+ function GetListCacheKey() {
3402
+ return Api.ECacheKey.Tileset;
3403
+ }
3404
+ Tileset.GetListCacheKey = GetListCacheKey;
3405
+ var EType;
3406
+ (function (EType) {
3407
+ EType["PointCloud"] = "POINT_CLOUD";
3408
+ EType["GeoMap"] = "GEO_MAP";
3409
+ EType["EntitiesMap"] = "ENTITIES_MAP";
3410
+ EType["EntitiesSet"] = "ENTITIES_SET";
3411
+ EType["Cad"] = "MODEL";
3412
+ EType["Terrain"] = "GEO_TERR";
3413
+ EType["ExternalTerrain"] = "EXTERNAL_TERR";
3414
+ EType["ExternalGeoMap"] = "EXTERNAL_MAP";
3415
+ })(EType = Tileset.EType || (Tileset.EType = {}));
3416
+ var EPivot;
3417
+ (function (EPivot) {
3418
+ EPivot["None"] = "none";
3419
+ EPivot["Box"] = "box";
3420
+ EPivot["Weight"] = "weight";
3421
+ EPivot["UCS"] = "ucs";
3422
+ })(EPivot = Tileset.EPivot || (Tileset.EPivot = {}));
3423
+ function Get(api, tilesetId, loadFiles) {
3424
+ if (loadFiles === void 0) { loadFiles = false; }
3425
+ return __awaiter(this, void 0, void 0, function () {
3426
+ var cacheData, req;
3427
+ return __generator(this, function (_a) {
3428
+ if (!tilesetId) {
3429
+ throw ("Tileset ID is required.");
3430
+ }
3431
+ cacheData = api.Cache.Get(GetCacheKey(tilesetId, loadFiles));
3432
+ if (cacheData) {
3433
+ return [2 /*return*/, cacheData];
3434
+ }
3435
+ req = api.GET("tileset/get/" + tilesetId + "?noFiles=" + (loadFiles ? 0 : 1));
3436
+ api.Cache.Set(GetCacheKey(tilesetId, loadFiles), req, Api.DEFAULT_CACHE_DURATION);
3437
+ return [2 /*return*/, req];
3438
+ });
3439
+ });
3440
+ }
3441
+ Tileset.Get = Get;
3442
+ function GetList(api) {
3443
+ return __awaiter(this, void 0, void 0, function () {
3444
+ var cacheData, req;
3445
+ var _this = this;
3446
+ return __generator(this, function (_a) {
3447
+ cacheData = api.Cache.Get(GetListCacheKey());
3448
+ if (cacheData) {
3449
+ return [2 /*return*/, cacheData];
3450
+ }
3451
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
3452
+ var data, e_1;
3453
+ return __generator(this, function (_a) {
3454
+ switch (_a.label) {
3455
+ case 0:
3456
+ _a.trys.push([0, 2, , 3]);
3457
+ return [4 /*yield*/, api.GET("tileset/getList")];
3458
+ case 1:
3459
+ data = _a.sent();
3460
+ res(data);
3461
+ return [3 /*break*/, 3];
3462
+ case 2:
3463
+ e_1 = _a.sent();
3464
+ rej(e_1);
3465
+ return [3 /*break*/, 3];
3466
+ case 3: return [2 /*return*/];
3467
+ }
3468
+ });
3469
+ }); });
3470
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
3471
+ return [2 /*return*/, req];
3472
+ });
3473
+ });
3474
+ }
3475
+ Tileset.GetList = GetList;
3476
+ function Delete(api, tilesetId) {
3477
+ return __awaiter(this, void 0, void 0, function () {
3478
+ return __generator(this, function (_a) {
3479
+ switch (_a.label) {
3480
+ case 0:
3481
+ if (!tilesetId) {
3482
+ throw ("Tileset ID is required.");
3483
+ }
3484
+ return [4 /*yield*/, api.DELETE("tileset/delete/" + tilesetId)];
3485
+ case 1:
3486
+ _a.sent();
3487
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Tileset + Api.ECacheKey.Id + tilesetId);
3488
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Tileset);
3489
+ return [2 /*return*/];
3490
+ }
3491
+ });
3492
+ });
3493
+ }
3494
+ Tileset.Delete = Delete;
3495
+ function Update(api, data) {
3496
+ return __awaiter(this, void 0, void 0, function () {
3497
+ var isNew, res;
3498
+ return __generator(this, function (_a) {
3499
+ switch (_a.label) {
3500
+ case 0:
3501
+ if (!(data === null || data === void 0 ? void 0 : data.name) || !(data === null || data === void 0 ? void 0 : data.type)) {
3502
+ throw ("Tileset name and type are required.");
3503
+ }
3504
+ isNew = !data.id;
3505
+ if (!isNew) return [3 /*break*/, 2];
3506
+ return [4 /*yield*/, api.GET("tileset/new?type=" + data.type + "&name=" + Api.Encode(data.name))];
3507
+ case 1:
3508
+ res = _a.sent();
3509
+ data = __assign(__assign({}, data), res);
3510
+ _a.label = 2;
3511
+ case 2: return [4 /*yield*/, api.post("tileset", data)];
3512
+ case 3:
3513
+ data = _a.sent();
3514
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Tileset + Api.ECacheKey.Id + data.id);
3515
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Tileset);
3516
+ return [2 /*return*/, data];
3517
+ }
3518
+ });
3519
+ });
3520
+ }
3521
+ Tileset.Update = Update;
3522
+ function UploadFile(api, tilesetId, file, onProgress) {
3523
+ return __awaiter(this, void 0, void 0, function () {
3524
+ return __generator(this, function (_a) {
3525
+ if (!tilesetId || !file) {
3526
+ throw ("Tileset ID and file are required.");
3527
+ }
3528
+ return [2 /*return*/, api.UPLOAD("tileset/uploadFile/" + tilesetId + "/files", file, { onProgress: onProgress })];
3529
+ });
3530
+ });
3531
+ }
3532
+ Tileset.UploadFile = UploadFile;
3533
+ function DeleteFile(api, tilesetId, file) {
3534
+ return __awaiter(this, void 0, void 0, function () {
3535
+ return __generator(this, function (_a) {
3536
+ switch (_a.label) {
3537
+ case 0:
3538
+ if (!tilesetId || !file) {
3539
+ throw ("Tileset ID and file are required.");
3540
+ }
3541
+ return [4 /*yield*/, api.DELETE("tileset/deleteFile/" + tilesetId + "/files/" + file)];
3542
+ case 1:
3543
+ _a.sent();
3544
+ api.Cache.Remove(GetCacheKey(tilesetId, true));
3545
+ return [2 /*return*/];
3546
+ }
3547
+ });
3548
+ });
3549
+ }
3550
+ Tileset.DeleteFile = DeleteFile;
3551
+ function UploadSrcFile(api, tilesetId, file, onProgress) {
3552
+ return __awaiter(this, void 0, void 0, function () {
3553
+ return __generator(this, function (_a) {
3554
+ switch (_a.label) {
3555
+ case 0:
3556
+ if (!tilesetId || !file) {
3557
+ throw ("Tileset ID and file are required.");
3558
+ }
3559
+ return [4 /*yield*/, api.UPLOAD("tileset/uploadFile/" + tilesetId + "/src", file, { onProgress: onProgress })];
3560
+ case 1:
3561
+ _a.sent();
3562
+ api.Cache.Remove(GetCacheKey(tilesetId, true));
3563
+ return [2 /*return*/];
3564
+ }
3565
+ });
3566
+ });
3567
+ }
3568
+ Tileset.UploadSrcFile = UploadSrcFile;
3569
+ function DeleteSrcFile(api, tilesetId, file) {
3570
+ return __awaiter(this, void 0, void 0, function () {
3571
+ return __generator(this, function (_a) {
3572
+ switch (_a.label) {
3573
+ case 0:
3574
+ if (!tilesetId || !file) {
3575
+ throw ("Tileset ID and file are required.");
3576
+ }
3577
+ return [4 /*yield*/, api.DELETE("tileset/deleteFile/" + tilesetId + "/src/" + file)];
3578
+ case 1:
3579
+ _a.sent();
3580
+ api.Cache.Remove(GetCacheKey(tilesetId, true));
3581
+ return [2 /*return*/];
3582
+ }
3583
+ });
3584
+ });
3585
+ }
3586
+ Tileset.DeleteSrcFile = DeleteSrcFile;
3587
+ function GetFileUrl(api, tilesetId, file) {
3588
+ if (!tilesetId) {
3589
+ throw ("Tileset ID is required.");
3590
+ }
3591
+ if (!file) {
3592
+ file = "";
3593
+ }
3594
+ return api.GetBaseUrl() + ("tileset/getFile/" + tilesetId + "/files/" + file);
3595
+ }
3596
+ Tileset.GetFileUrl = GetFileUrl;
3597
+ function GetSrcFileUrl(api, tilesetId, file) {
3598
+ if (!tilesetId) {
3599
+ throw ("Tileset ID is required.");
3600
+ }
3601
+ if (!file) {
3602
+ file = "";
3603
+ }
3604
+ return api.GetBaseUrl() + ("tileset/getFile/" + tilesetId + "/src/" + file);
3605
+ }
3606
+ Tileset.GetSrcFileUrl = GetSrcFileUrl;
3607
+ function GetPublicFileUrl(api, tilesetId, file) {
3608
+ if (!tilesetId) {
3609
+ throw ("Tileset ID is required.");
3610
+ }
3611
+ if (!file) {
3612
+ file = "";
3613
+ }
3614
+ return api.GetBaseUrl() + ("tileset/file/" + tilesetId + "/" + file);
3615
+ }
3616
+ Tileset.GetPublicFileUrl = GetPublicFileUrl;
3617
+ function Generate(api, tilesetId) {
3618
+ return __awaiter(this, void 0, void 0, function () {
3619
+ var res;
3620
+ return __generator(this, function (_a) {
3621
+ switch (_a.label) {
3622
+ case 0:
3623
+ if (!tilesetId) {
3624
+ throw ("Tileset ID is required.");
3625
+ }
3626
+ return [4 /*yield*/, api.GET("tileset/generate/" + tilesetId)];
3627
+ case 1:
3628
+ res = _a.sent();
3629
+ return [2 /*return*/, res.ID];
3630
+ }
3631
+ });
3632
+ });
3633
+ }
3634
+ Tileset.Generate = Generate;
3635
+ var Publish;
3636
+ (function (Publish) {
3637
+ function GetCacheKey(accountId, tilesetId) {
3638
+ if (!tilesetId) {
3639
+ tilesetId = "";
3640
+ }
3641
+ return Api.ECacheKey.PublishTileset + Api.ECacheKey.Id + accountId + Api.ECacheKey.Id + tilesetId;
3642
+ }
3643
+ Publish.GetCacheKey = GetCacheKey;
3644
+ function Update(api, data) {
3645
+ return __awaiter(this, void 0, void 0, function () {
3646
+ var res, req;
3647
+ return __generator(this, function (_a) {
3648
+ switch (_a.label) {
3649
+ case 0:
3650
+ if (!(data === null || data === void 0 ? void 0 : data["Tileset.ID"]) || !(data === null || data === void 0 ? void 0 : data["PublishedBy.ClientAccount.ID"]) || !(data === null || data === void 0 ? void 0 : data["PublishedBy.User.ID"])) {
3651
+ throw ("Tileset ID, client account ID, and user ID are required.");
3652
+ }
3653
+ if (!data.ID) {
3654
+ data.ID = 0;
3655
+ }
3656
+ return [4 /*yield*/, api.POST("tileset/" + data.ID, data)];
3657
+ case 1:
3658
+ res = _a.sent();
3659
+ req = {
3660
+ "ClientAccount.ID": data["EnabledFor.ClientAccount.ID"]
3661
+ };
3662
+ data.ID = res.ID;
3663
+ return [4 /*yield*/, api.POST("tileset/" + data.ID + "/enableForAccounts", req)];
3664
+ case 2:
3665
+ _a.sent();
3666
+ api.Cache.Remove(GetCacheKey(data["PublishedBy.ClientAccount.ID"], data["Tileset.ID"]));
3667
+ api.Cache.Remove(GetCacheKey(data["PublishedBy.ClientAccount.ID"]));
3668
+ return [2 /*return*/, data];
3669
+ }
3670
+ });
3671
+ });
3672
+ }
3673
+ Publish.Update = Update;
3674
+ function Get(api, accountId, tilesetId) {
3675
+ return __awaiter(this, void 0, void 0, function () {
3676
+ var cacheData, req;
3677
+ return __generator(this, function (_a) {
3678
+ if (!accountId || !tilesetId) {
3679
+ throw ("Client account ID and tileset ID are required.");
3680
+ }
3681
+ cacheData = api.Cache.Get(GetCacheKey(accountId, tilesetId));
3682
+ if (cacheData) {
3683
+ return [2 /*return*/, cacheData];
3684
+ }
3685
+ req = api.GET("tilesetByPublisher/" + accountId + "/" + tilesetId);
3686
+ api.Cache.Set(GetCacheKey(accountId, tilesetId), req);
3687
+ return [2 /*return*/, req];
3688
+ });
3689
+ });
3690
+ }
3691
+ Publish.Get = Get;
3692
+ function GetList(api, accountId) {
3693
+ return __awaiter(this, void 0, void 0, function () {
3694
+ var cacheData, req;
3695
+ var _this = this;
3696
+ return __generator(this, function (_a) {
3697
+ if (!accountId) {
3698
+ throw ("Client account ID is required.");
3699
+ }
3700
+ cacheData = api.Cache.Get(GetCacheKey(accountId));
3701
+ if (cacheData) {
3702
+ return [2 /*return*/, cacheData];
3703
+ }
3704
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
3705
+ var data, e_2;
3706
+ return __generator(this, function (_a) {
3707
+ switch (_a.label) {
3708
+ case 0:
3709
+ _a.trys.push([0, 2, , 3]);
3710
+ return [4 /*yield*/, api.GET("tilesets/enabledForAccount/" + accountId)];
3711
+ case 1:
3712
+ data = _a.sent();
3713
+ res(data.Items);
3714
+ return [3 /*break*/, 3];
3715
+ case 2:
3716
+ e_2 = _a.sent();
3717
+ rej(e_2);
3718
+ return [3 /*break*/, 3];
3719
+ case 3: return [2 /*return*/];
3720
+ }
3721
+ });
3722
+ }); });
3723
+ api.Cache.Set(GetCacheKey(accountId), req);
3724
+ return [2 /*return*/, req];
3725
+ });
3726
+ });
3727
+ }
3728
+ Publish.GetList = GetList;
3729
+ })(Publish = Tileset.Publish || (Tileset.Publish = {}));
3730
+ })(Tileset || (Tileset = {}));
3731
+
3732
+ var MenuItem;
3733
+ (function (MenuItem) {
3734
+ var EType;
3735
+ (function (EType) {
3736
+ EType["None"] = "NONE";
3737
+ EType["BruceEntities"] = "BruceEntity";
3738
+ EType["BruceEntity"] = "SingleEntity";
3739
+ EType["Osm"] = "OSMBuildingsTileset";
3740
+ EType["CadTileset"] = "ModelTileset";
3741
+ EType["ArbTileset"] = "Cesium3DTileset";
3742
+ EType["Kml"] = "StaticKML";
3743
+ EType["EntitiesTileset"] = "EntitiesTileset";
3744
+ EType["EntitiesRaster"] = "RasterEntitiesTileset";
3745
+ EType["PointCloud"] = "PointCloudTileset";
3746
+ })(EType = MenuItem.EType || (MenuItem.EType = {}));
3747
+ function CreateFromEntityId(entityId, typeId, styleId) {
3748
+ return {
3749
+ id: ObjectUtils.UId(),
3750
+ Type: EType.BruceEntity,
3751
+ Caption: "Generated Entity Menu Item",
3752
+ BruceEntity: {
3753
+ "EntityType.ID": typeId,
3754
+ EntityId: entityId
3755
+ },
3756
+ CameraZoomSettings: [
3757
+ {
3758
+ DisplayType: MenuItemZoomControl.EDisplayType.Model3D,
3759
+ MaxZoom: 8000,
3760
+ MinZoom: 0,
3761
+ StyleID: styleId
3762
+ }
3763
+ ]
3764
+ };
3765
+ }
3766
+ MenuItem.CreateFromEntityId = CreateFromEntityId;
3767
+ function CreateFromTypeId(typeId, styleId) {
3768
+ return {
3769
+ id: ObjectUtils.UId(),
3770
+ Type: EType.BruceEntities,
3771
+ Caption: "Generated Entity Type Menu Item",
3772
+ BruceEntity: {
3773
+ "EntityType.ID": typeId
3774
+ },
3775
+ CameraZoomSettings: [
3776
+ {
3777
+ DisplayType: MenuItemZoomControl.EDisplayType.Model3D,
3778
+ MaxZoom: 8000,
3779
+ MinZoom: 0,
3780
+ StyleID: styleId
3781
+ }
3782
+ ]
3783
+ };
3784
+ }
3785
+ MenuItem.CreateFromTypeId = CreateFromTypeId;
3786
+ function CreateFromTilesetId(tilesetId, type) {
3787
+ if (type === Tileset.EType.Cad) {
3788
+ return {
3789
+ id: ObjectUtils.UId(),
3790
+ Type: EType.CadTileset,
3791
+ Caption: "Generated CAD Menu Item",
3792
+ FlyTo: false,
3793
+ tileset: {
3794
+ TilesetID: tilesetId
3795
+ }
3796
+ };
3797
+ }
3798
+ else if (type == Tileset.EType.EntitiesSet) {
3799
+ return {
3800
+ id: ObjectUtils.UId(),
3801
+ Type: EType.EntitiesTileset,
3802
+ Caption: "Generated Entities Menu Item",
3803
+ FlyTo: false,
3804
+ tileset: {
3805
+ TilesetID: tilesetId
3806
+ }
3807
+ };
3808
+ }
3809
+ else if (type == Tileset.EType.PointCloud) {
3810
+ return {
3811
+ id: ObjectUtils.UId(),
3812
+ Type: EType.PointCloud,
3813
+ Caption: "Generated Point Cloud Menu Item",
3814
+ FlyTo: false,
3815
+ tileset: {
3816
+ TilesetID: tilesetId
3817
+ }
3818
+ };
3819
+ }
3820
+ else if (type == Tileset.EType.EntitiesMap) {
3821
+ return {
3822
+ id: ObjectUtils.UId(),
3823
+ Type: EType.EntitiesRaster,
3824
+ Caption: "Generated Entities Menu Item",
3825
+ tileset: {
3826
+ TilesetID: tilesetId
3827
+ }
3828
+ };
3829
+ }
3830
+ throw ("Tileset type not supported.");
3831
+ }
3832
+ MenuItem.CreateFromTilesetId = CreateFromTilesetId;
3833
+ })(MenuItem || (MenuItem = {}));
3834
+
3835
+ var ProjectViewBookmark;
3836
+ (function (ProjectViewBookmark) {
3837
+ function GetCacheKey(viewId, bookmarkId) {
3838
+ return "" + Api.ECacheKey.ProjectViewBookmark + Api.ECacheKey.Id + viewId + Api.ECacheKey.Id + bookmarkId;
3839
+ }
3840
+ ProjectViewBookmark.GetCacheKey = GetCacheKey;
3841
+ function GetListCacheKey() {
3842
+ return Api.ECacheKey.ProjectViewBookmark;
3843
+ }
3844
+ ProjectViewBookmark.GetListCacheKey = GetListCacheKey;
3845
+ function Get(api, viewId, bookmarkId) {
3846
+ return __awaiter(this, void 0, void 0, function () {
3847
+ var key, cacheData, req;
3848
+ return __generator(this, function (_a) {
3849
+ if (!viewId || !bookmarkId) {
3850
+ throw ("View ID and Bookmark ID are required.");
3851
+ }
3852
+ key = GetCacheKey(viewId, bookmarkId);
3853
+ cacheData = api.Cache.Get(key);
3854
+ if (cacheData) {
3855
+ return [2 /*return*/, cacheData];
3856
+ }
3857
+ req = api.GET("ui.view/" + viewId + "/slide/" + bookmarkId, Api.PrepReqParams());
3858
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
3859
+ return [2 /*return*/, req];
3860
+ });
3861
+ });
3862
+ }
3863
+ ProjectViewBookmark.Get = Get;
3864
+ function Delete(api, viewId, bookmarkId) {
3865
+ return __awaiter(this, void 0, void 0, function () {
3866
+ return __generator(this, function (_a) {
3867
+ switch (_a.label) {
3868
+ case 0:
3869
+ if (!viewId || !bookmarkId) {
3870
+ throw ("View ID and Bookmark ID are required.");
3871
+ }
3872
+ return [4 /*yield*/, api.DELETE("ui.view/" + viewId + "/slide/" + bookmarkId, Api.PrepReqParams())];
3873
+ case 1:
3874
+ _a.sent();
3875
+ api.Cache.Remove(GetCacheKey(viewId, bookmarkId));
3876
+ api.Cache.Remove(GetListCacheKey());
3877
+ return [2 /*return*/];
3878
+ }
3879
+ });
3880
+ });
3881
+ }
3882
+ ProjectViewBookmark.Delete = Delete;
3883
+ function GetList(api, viewId) {
3884
+ return __awaiter(this, void 0, void 0, function () {
3885
+ var cacheData, req;
3886
+ var _this = this;
3887
+ return __generator(this, function (_a) {
3888
+ if (!viewId) {
3889
+ throw ("View ID is required.");
3890
+ }
3891
+ cacheData = api.Cache.Get(GetListCacheKey());
3892
+ if (cacheData) {
3893
+ return [2 /*return*/, cacheData];
3894
+ }
3895
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
3896
+ var data, e_1;
3897
+ return __generator(this, function (_a) {
3898
+ switch (_a.label) {
3899
+ case 0:
3900
+ _a.trys.push([0, 2, , 3]);
3901
+ return [4 /*yield*/, api.GET("ui.view/" + viewId + "/slides", Api.PrepReqParams())];
3902
+ case 1:
3903
+ data = _a.sent();
3904
+ res(data.Items);
3905
+ return [3 /*break*/, 3];
3906
+ case 2:
3907
+ e_1 = _a.sent();
3908
+ rej(e_1);
3909
+ return [3 /*break*/, 3];
3910
+ case 3: return [2 /*return*/];
3911
+ }
3912
+ });
3913
+ }); });
3914
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
3915
+ return [2 /*return*/, req];
3916
+ });
3917
+ });
3918
+ }
3919
+ ProjectViewBookmark.GetList = GetList;
3920
+ function Update(api, viewId, data) {
3921
+ return __awaiter(this, void 0, void 0, function () {
3922
+ return __generator(this, function (_a) {
3923
+ switch (_a.label) {
3924
+ case 0:
3925
+ if (!(data === null || data === void 0 ? void 0 : data.ID)) {
3926
+ data.ID = ObjectUtils.UId();
3927
+ }
3928
+ if (!(data === null || data === void 0 ? void 0 : data.Title)) {
3929
+ data.Title = data.ID;
3930
+ }
3931
+ return [4 /*yield*/, api.post("ui.view/" + viewId + "/slide/" + data.ID, data, Api.PrepReqParams())];
3932
+ case 1:
3933
+ data = _a.sent();
3934
+ api.Cache.Remove(GetCacheKey(viewId, data.ID));
3935
+ api.Cache.Remove(GetListCacheKey());
3936
+ return [2 /*return*/, data];
3937
+ }
3938
+ });
3939
+ });
3940
+ }
3941
+ ProjectViewBookmark.Update = Update;
3942
+ })(ProjectViewBookmark || (ProjectViewBookmark = {}));
3943
+
3944
+ var ProjectView;
3945
+ (function (ProjectView) {
3946
+ function GetCacheKey(viewId) {
3947
+ return "" + Api.ECacheKey.ProjectView + Api.ECacheKey.Id + viewId;
3948
+ }
3949
+ ProjectView.GetCacheKey = GetCacheKey;
3950
+ function GetListCacheKey() {
3951
+ return Api.ECacheKey.ProjectView;
3952
+ }
3953
+ ProjectView.GetListCacheKey = GetListCacheKey;
3954
+ function Get(api, viewId) {
3955
+ return __awaiter(this, void 0, void 0, function () {
3956
+ var key, cacheData, req;
3957
+ return __generator(this, function (_a) {
3958
+ if (!viewId) {
3959
+ throw ("View ID is required.");
3960
+ }
3961
+ key = GetCacheKey(viewId);
3962
+ cacheData = api.Cache.Get(key);
3963
+ if (cacheData) {
3964
+ return [2 /*return*/, cacheData];
3965
+ }
3966
+ req = api.GET("ui.view/" + viewId, Api.PrepReqParams());
3967
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
3968
+ return [2 /*return*/, req];
3969
+ });
3970
+ });
3971
+ }
3972
+ ProjectView.Get = Get;
3973
+ function GetList(api) {
3974
+ return __awaiter(this, void 0, void 0, function () {
3975
+ var cacheData, req;
3976
+ var _this = this;
3977
+ return __generator(this, function (_a) {
3978
+ cacheData = api.Cache.Get(GetListCacheKey());
3979
+ if (cacheData) {
3980
+ return [2 /*return*/, cacheData];
3981
+ }
3982
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
3983
+ var data, e_1;
3984
+ return __generator(this, function (_a) {
3985
+ switch (_a.label) {
3986
+ case 0:
3987
+ _a.trys.push([0, 2, , 3]);
3988
+ return [4 /*yield*/, api.GET("ui.view/list", Api.PrepReqParams())];
3989
+ case 1:
3990
+ data = _a.sent();
3991
+ res(data.Items);
3992
+ return [3 /*break*/, 3];
3993
+ case 2:
3994
+ e_1 = _a.sent();
3995
+ rej(e_1);
3996
+ return [3 /*break*/, 3];
3997
+ case 3: return [2 /*return*/];
3998
+ }
3999
+ });
4000
+ }); });
4001
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
4002
+ return [2 /*return*/, req];
4003
+ });
4004
+ });
4005
+ }
4006
+ ProjectView.GetList = GetList;
4007
+ function Delete(api, viewId) {
4008
+ return __awaiter(this, void 0, void 0, function () {
4009
+ return __generator(this, function (_a) {
4010
+ switch (_a.label) {
4011
+ case 0:
4012
+ if (!viewId) {
4013
+ throw ("View ID is required.");
4014
+ }
4015
+ return [4 /*yield*/, api.DELETE("ui.view/" + viewId, Api.PrepReqParams())];
4016
+ case 1:
4017
+ _a.sent();
4018
+ api.Cache.Remove(GetCacheKey(viewId));
4019
+ api.Cache.Remove(GetListCacheKey());
4020
+ return [2 /*return*/];
4021
+ }
4022
+ });
4023
+ });
4024
+ }
4025
+ ProjectView.Delete = Delete;
4026
+ function Update(api, data) {
4027
+ return __awaiter(this, void 0, void 0, function () {
4028
+ return __generator(this, function (_a) {
4029
+ switch (_a.label) {
4030
+ case 0:
4031
+ if (!(data === null || data === void 0 ? void 0 : data.ID)) {
4032
+ data.ID = ObjectUtils.UId();
4033
+ }
4034
+ if (!(data === null || data === void 0 ? void 0 : data.Name)) {
4035
+ data.Name = data.ID;
4036
+ }
4037
+ return [4 /*yield*/, api.post("ui.view", data, Api.PrepReqParams())];
4038
+ case 1:
4039
+ data = _a.sent();
4040
+ api.Cache.Remove(GetCacheKey(data.ID));
4041
+ api.Cache.Remove(GetListCacheKey());
4042
+ return [2 /*return*/, data];
4043
+ }
4044
+ });
4045
+ });
4046
+ }
4047
+ ProjectView.Update = Update;
4048
+ })(ProjectView || (ProjectView = {}));
4049
+
4050
+ var PendingAction;
4051
+ (function (PendingAction) {
4052
+ var EStatus;
4053
+ (function (EStatus) {
4054
+ EStatus["InProgress"] = "IN_PROGRESS";
4055
+ EStatus["Cancelled"] = "CANCELLED";
4056
+ EStatus["Complete"] = "COMPLETE";
4057
+ EStatus["Failed"] = "FAILED";
4058
+ })(EStatus = PendingAction.EStatus || (PendingAction.EStatus = {}));
4059
+ function Get(api, actionId) {
4060
+ return __awaiter(this, void 0, void 0, function () {
4061
+ return __generator(this, function (_a) {
4062
+ if (!actionId) {
4063
+ throw ("Action ID is required.");
4064
+ }
4065
+ return [2 /*return*/, api.GET("pendingAction/" + actionId, Api.PrepReqParams())];
4066
+ });
4067
+ });
4068
+ }
4069
+ PendingAction.Get = Get;
4070
+ function GetRelevantList(api, stricter) {
4071
+ if (stricter === void 0) { stricter = false; }
4072
+ return __awaiter(this, void 0, void 0, function () {
4073
+ var data;
4074
+ return __generator(this, function (_a) {
4075
+ switch (_a.label) {
4076
+ case 0: return [4 /*yield*/, api.GET("pendingActions/important?Update=" + stricter, Api.PrepReqParams())];
4077
+ case 1:
4078
+ data = _a.sent();
4079
+ return [2 /*return*/, data.Items];
4080
+ }
4081
+ });
4082
+ });
4083
+ }
4084
+ PendingAction.GetRelevantList = GetRelevantList;
4085
+ function GetMessages(api, actionId, order, startIndex, amount) {
4086
+ return __awaiter(this, void 0, void 0, function () {
4087
+ var args, data;
4088
+ return __generator(this, function (_a) {
4089
+ switch (_a.label) {
4090
+ case 0:
4091
+ if (amount == null) {
4092
+ amount = 500;
4093
+ }
4094
+ if (startIndex == null) {
4095
+ startIndex = 0;
4096
+ }
4097
+ if (order == null) {
4098
+ order = Api.ESortOrder.Asc;
4099
+ }
4100
+ args = "?SortOrder=" + (order == Api.ESortOrder.Desc ? "DESC" : "ASC") + "&PageSize=" + amount + "&PageIndex=" + startIndex;
4101
+ return [4 /*yield*/, api.GET("pendingAction/" + actionId + "/progressMessages" + args, Api.PrepReqParams())];
4102
+ case 1:
4103
+ data = _a.sent();
4104
+ return [2 /*return*/, data.Items];
4105
+ }
4106
+ });
4107
+ });
4108
+ }
4109
+ PendingAction.GetMessages = GetMessages;
4110
+ })(PendingAction || (PendingAction = {}));
4111
+
4112
+ var Style;
4113
+ (function (Style) {
4114
+ function GetCacheKey(id) {
4115
+ return Api.ECacheKey.Style + Api.ECacheKey.Id + id;
4116
+ }
4117
+ Style.GetCacheKey = GetCacheKey;
4118
+ function GetListCacheKey() {
4119
+ return Api.ECacheKey.Style;
4120
+ }
4121
+ Style.GetListCacheKey = GetListCacheKey;
4122
+ var EType;
4123
+ (function (EType) {
4124
+ EType["Entity"] = "ENTITY";
4125
+ EType["EntityRelationship"] = "ENTITY_RELATIONSHIP";
4126
+ })(EType = Style.EType || (Style.EType = {}));
4127
+ function GetList(api) {
4128
+ var _this = this;
4129
+ var cacheData = api.Cache.Get(GetListCacheKey());
4130
+ if (cacheData) {
4131
+ return cacheData;
4132
+ }
4133
+ var req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
4134
+ var data, e_1;
4135
+ return __generator(this, function (_a) {
4136
+ switch (_a.label) {
4137
+ case 0:
4138
+ _a.trys.push([0, 2, , 3]);
4139
+ return [4 /*yield*/, api.GET("ui.entityDisplaySettings", Api.PrepReqParams())];
4140
+ case 1:
4141
+ data = _a.sent();
4142
+ res(data.Items);
4143
+ return [3 /*break*/, 3];
4144
+ case 2:
4145
+ e_1 = _a.sent();
4146
+ rej(e_1);
4147
+ return [3 /*break*/, 3];
4148
+ case 3: return [2 /*return*/];
4149
+ }
4150
+ });
4151
+ }); });
4152
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
4153
+ return req;
4154
+ }
4155
+ Style.GetList = GetList;
4156
+ function Get(api, id) {
4157
+ if (!id) {
4158
+ throw ("Style ID is required.");
4159
+ }
4160
+ var cacheData = api.Cache.Get(GetCacheKey(id));
4161
+ if (cacheData) {
4162
+ return cacheData;
4163
+ }
4164
+ var req = api.GET("ui.entityDisplaySetting/" + id, Api.PrepReqParams());
4165
+ api.Cache.Set(GetCacheKey(id), req, Api.DEFAULT_CACHE_DURATION);
4166
+ return req;
4167
+ }
4168
+ Style.Get = Get;
4169
+ function Update(api, data) {
4170
+ return __awaiter(this, void 0, void 0, function () {
4171
+ return __generator(this, function (_a) {
4172
+ switch (_a.label) {
4173
+ case 0:
4174
+ if (!(data === null || data === void 0 ? void 0 : data.Name)) {
4175
+ throw ("Style name is required.");
4176
+ }
4177
+ if (!data.ID) {
4178
+ data.ID = 0;
4179
+ }
4180
+ return [4 /*yield*/, api.POST("ui.entityDisplaySetting/" + data.ID, data, Api.PrepReqParams())];
4181
+ case 1:
4182
+ data = _a.sent();
4183
+ api.Cache.Remove(GetCacheKey(data.ID));
4184
+ api.Cache.Remove(GetListCacheKey());
4185
+ return [2 /*return*/, data];
4186
+ }
4187
+ });
4188
+ });
4189
+ }
4190
+ Style.Update = Update;
4191
+ function Delete(api, id) {
4192
+ return __awaiter(this, void 0, void 0, function () {
4193
+ return __generator(this, function (_a) {
4194
+ switch (_a.label) {
4195
+ case 0:
4196
+ if (!id) {
4197
+ throw ("Style ID is required.");
4198
+ }
4199
+ return [4 /*yield*/, api.DELETE("ui.entityDisplaySetting/" + id, Api.PrepReqParams())];
4200
+ case 1:
4201
+ _a.sent();
4202
+ api.Cache.Remove(GetCacheKey(id));
4203
+ api.Cache.Remove(GetListCacheKey());
4204
+ return [2 /*return*/];
4205
+ }
4206
+ });
4207
+ });
4208
+ }
4209
+ Style.Delete = Delete;
4210
+ })(Style || (Style = {}));
4211
+
4212
+ var TilesetEntitiesMapTiles;
4213
+ (function (TilesetEntitiesMapTiles) {
4214
+ var ETileSize;
4215
+ (function (ETileSize) {
4216
+ ETileSize[ETileSize["IMG_256"] = 256] = "IMG_256";
4217
+ ETileSize[ETileSize["IMG_512"] = 512] = "IMG_512";
4218
+ ETileSize[ETileSize["IMG_1024"] = 1024] = "IMG_1024";
4219
+ ETileSize[ETileSize["IMG_2048"] = 2048] = "IMG_2048";
4220
+ })(ETileSize = TilesetEntitiesMapTiles.ETileSize || (TilesetEntitiesMapTiles.ETileSize = {}));
4221
+ })(TilesetEntitiesMapTiles || (TilesetEntitiesMapTiles = {}));
4222
+
4223
+ var TilesetExtMapTiles;
4224
+ (function (TilesetExtMapTiles) {
4225
+ var EType;
4226
+ (function (EType) {
4227
+ EType["TileMapImagery"] = "TileMapImagery";
4228
+ EType["OpenStreetMapImagery"] = "OpenStreetMapImagery";
4229
+ EType["MapBoxImagery"] = "MapBoxImagery";
4230
+ EType["CesiumIon"] = "CesiumIon";
4231
+ })(EType = TilesetExtMapTiles.EType || (TilesetExtMapTiles.EType = {}));
4232
+ })(TilesetExtMapTiles || (TilesetExtMapTiles = {}));
4233
+
4234
+ var Ucs;
4235
+ (function (Ucs) {
4236
+ function GetCacheKey(id, expandUsage) {
4237
+ return Api.ECacheKey.Ucs + Api.ECacheKey.Id + id + Api.ECacheKey + expandUsage;
4238
+ }
4239
+ Ucs.GetCacheKey = GetCacheKey;
4240
+ function GetListCacheKey() {
4241
+ return Api.ECacheKey.Ucs;
4242
+ }
4243
+ Ucs.GetListCacheKey = GetListCacheKey;
4244
+ var EState;
4245
+ (function (EState) {
4246
+ EState["Undefined"] = "undef";
4247
+ EState["Prepared"] = "ready";
4248
+ })(EState = Ucs.EState || (Ucs.EState = {}));
4249
+ function Get(api, ucsId, expandUsage) {
4250
+ return __awaiter(this, void 0, void 0, function () {
4251
+ var cacheData, req;
4252
+ return __generator(this, function (_a) {
4253
+ if (!ucsId) {
4254
+ throw ("UCS ID is required.");
4255
+ }
4256
+ if (!expandUsage) {
4257
+ expandUsage = false;
4258
+ }
4259
+ cacheData = api.Cache.Get(GetCacheKey(ucsId, expandUsage));
4260
+ if (cacheData) {
4261
+ return [2 /*return*/, cacheData];
4262
+ }
4263
+ req = api.GET("ucs/" + ucsId);
4264
+ api.Cache.Set(GetCacheKey(ucsId, expandUsage), req, Api.DEFAULT_CACHE_DURATION);
4265
+ return [2 /*return*/, req];
4266
+ });
4267
+ });
4268
+ }
4269
+ Ucs.Get = Get;
4270
+ function Delete(api, ucsId) {
4271
+ return __awaiter(this, void 0, void 0, function () {
4272
+ return __generator(this, function (_a) {
4273
+ switch (_a.label) {
4274
+ case 0:
4275
+ if (!ucsId) {
4276
+ throw ("UCS ID is required.");
4277
+ }
4278
+ return [4 /*yield*/, api.DELETE("ucs/" + ucsId)];
4279
+ case 1:
4280
+ _a.sent();
4281
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Ucs + Api.ECacheKey.Id + ucsId);
4282
+ api.Cache.Remove(GetListCacheKey());
4283
+ return [2 /*return*/];
4284
+ }
4285
+ });
4286
+ });
4287
+ }
4288
+ Ucs.Delete = Delete;
4289
+ function GetList(api) {
4290
+ return __awaiter(this, void 0, void 0, function () {
4291
+ var cacheData, req;
4292
+ return __generator(this, function (_a) {
4293
+ cacheData = api.Cache.Get(GetListCacheKey());
4294
+ if (cacheData) {
4295
+ return [2 /*return*/, cacheData];
4296
+ }
4297
+ req = api.GET("ucs");
4298
+ api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
4299
+ return [2 /*return*/, req];
4300
+ });
4301
+ });
4302
+ }
4303
+ Ucs.GetList = GetList;
4304
+ function Update(api, data) {
4305
+ return __awaiter(this, void 0, void 0, function () {
4306
+ return __generator(this, function (_a) {
4307
+ switch (_a.label) {
4308
+ case 0:
4309
+ if (!(data === null || data === void 0 ? void 0 : data.name)) {
4310
+ throw ("UCS name is required.");
4311
+ }
4312
+ return [4 /*yield*/, api.post("ucs" + (!data.id ? "" : "/" + data.id), data)];
4313
+ case 1:
4314
+ data = _a.sent();
4315
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Ucs + Api.ECacheKey.Id + data.id);
4316
+ api.Cache.Remove(GetListCacheKey());
4317
+ return [2 /*return*/, data];
4318
+ }
4319
+ });
4320
+ });
4321
+ }
4322
+ Ucs.Update = Update;
4323
+ })(Ucs || (Ucs = {}));
4324
+
4325
+ var Permission;
4326
+ (function (Permission) {
4327
+ var EPerm;
4328
+ (function (EPerm) {
4329
+ EPerm["ADMIN"] = "ADMIN";
4330
+ EPerm["LOGIN"] = "LOGIN";
4331
+ EPerm["DELETE_ENTITY_TYPE"] = "DELETE_ENTITY_TYPE";
4332
+ EPerm["CREATE_ENTITY_TYPE"] = "CREATE_ENTITY_TYPE";
4333
+ EPerm["UPDATE_ENTITY_TYPE"] = "UPDATE_ENTITY_TYPE";
4334
+ })(EPerm = Permission.EPerm || (Permission.EPerm = {}));
4335
+ var EPermPrefix;
4336
+ (function (EPermPrefix) {
4337
+ EPermPrefix["ACCESS_PROJECT_VIEW"] = "UIVIEW_";
4338
+ EPermPrefix["MANAGE_PROJECT_VIEW_BOOKMARKS"] = "UIVIEW_MANAGE_BOOKMARKS_";
4339
+ EPermPrefix["ACCESS_TILESET"] = "TILESET_";
4340
+ })(EPermPrefix = Permission.EPermPrefix || (Permission.EPermPrefix = {}));
4341
+ })(Permission || (Permission = {}));
4342
+
4343
+ var Session;
4344
+ (function (Session) {
4345
+ function GetCacheKey(sessionId) {
4346
+ return "" + Api.ECacheKey.Session + Api.ECacheKey.Id + sessionId;
4347
+ }
4348
+ function Get(api, sessionId) {
4349
+ return __awaiter(this, void 0, void 0, function () {
4350
+ var key, cacheData, req;
4351
+ return __generator(this, function (_a) {
4352
+ if (!sessionId) {
4353
+ throw ("Session ID is required.");
4354
+ }
4355
+ key = GetCacheKey(sessionId);
4356
+ cacheData = api.Cache.Get(key);
4357
+ if (cacheData) {
4358
+ return [2 /*return*/, cacheData];
4359
+ }
4360
+ req = api.GET("session/" + sessionId);
4361
+ api.Cache.Set(key, req, Api.DEFAULT_CACHE_DURATION);
4362
+ return [2 /*return*/, req];
4363
+ });
4364
+ });
4365
+ }
4366
+ Session.Get = Get;
4367
+ function Login(api, username, password, accountId) {
4368
+ return __awaiter(this, void 0, void 0, function () {
4369
+ var data, ssid;
4370
+ return __generator(this, function (_a) {
4371
+ switch (_a.label) {
4372
+ case 0:
4373
+ if (!username || !password) {
4374
+ throw ("Username and password are required.");
4375
+ }
4376
+ return [4 /*yield*/, api.POST("login", {
4377
+ account: accountId ? accountId : "",
4378
+ login: username,
4379
+ password: password
4380
+ })];
4381
+ case 1:
4382
+ data = _a.sent();
4383
+ ssid = data === null || data === void 0 ? void 0 : data.ID;
4384
+ api.SetSessionId(ssid);
4385
+ api.Cache.Remove(GetCacheKey(ssid));
4386
+ return [2 /*return*/, data];
4387
+ }
4388
+ });
4389
+ });
4390
+ }
4391
+ Session.Login = Login;
4392
+ function Logout(api) {
4393
+ return __awaiter(this, void 0, void 0, function () {
4394
+ var ssid;
4395
+ return __generator(this, function (_a) {
4396
+ switch (_a.label) {
4397
+ case 0:
4398
+ ssid = api.GetSessionId();
4399
+ if (!ssid) return [3 /*break*/, 2];
4400
+ return [4 /*yield*/, api.POST("logout", null)];
4401
+ case 1:
4402
+ _a.sent();
4403
+ api.SetSessionId(null);
4404
+ api.Cache.Remove(GetCacheKey(ssid));
4405
+ _a.label = 2;
4406
+ case 2: return [2 /*return*/];
4407
+ }
4408
+ });
4409
+ });
4410
+ }
4411
+ Session.Logout = Logout;
4412
+ function IsPermEnabled(session, perm) {
4413
+ var _a, _b;
4414
+ if (!perm) {
4415
+ throw ("Perm is required.");
4416
+ }
4417
+ perm = perm.toLocaleUpperCase();
4418
+ var accessPerms = (_b = (_a = session.AccessPermissions) === null || _a === void 0 ? void 0 : _a.EnabledFeatures) !== null && _b !== void 0 ? _b : [];
4419
+ return accessPerms.findIndex(function (x) { return x.toLocaleUpperCase() == perm; }) > -1;
4420
+ }
4421
+ Session.IsPermEnabled = IsPermEnabled;
4422
+ function IsSuperPermEnabled(session, perm) {
4423
+ var _a, _b;
4424
+ if (!perm) {
4425
+ throw ("Perm is required.");
4426
+ }
4427
+ perm = perm.toLocaleUpperCase();
4428
+ var accessPerms = (_b = (_a = session.HypeportalAccessPermisssions) === null || _a === void 0 ? void 0 : _a.EnabledFeatures) !== null && _b !== void 0 ? _b : [];
4429
+ return accessPerms.findIndex(function (x) { return x.toLocaleUpperCase() == perm; }) > -1;
4430
+ }
4431
+ Session.IsSuperPermEnabled = IsSuperPermEnabled;
4432
+ function IsAccountAdmin(session) {
4433
+ return IsPermEnabled(session, Permission.EPerm.ADMIN);
4434
+ }
4435
+ Session.IsAccountAdmin = IsAccountAdmin;
4436
+ function IsSuperAdmin(session) {
4437
+ return IsSuperPermEnabled(session, Permission.EPerm.ADMIN);
4438
+ }
4439
+ Session.IsSuperAdmin = IsSuperAdmin;
4440
+ })(Session || (Session = {}));
4441
+
4442
+ var UserGroup;
4443
+ (function (UserGroup) {
4444
+ function GetByName(api, accountId, name) {
4445
+ return __awaiter(this, void 0, void 0, function () {
4446
+ return __generator(this, function (_a) {
4447
+ if (!name || !accountId) {
4448
+ throw ("Name and AccountID are required.");
4449
+ }
4450
+ return [2 /*return*/, api.GET("account/" + accountId + "/userGroupByName/" + name)];
4451
+ });
4452
+ });
4453
+ }
4454
+ UserGroup.GetByName = GetByName;
4455
+ function GetUsers(api, accountId, id) {
4456
+ return __awaiter(this, void 0, void 0, function () {
4457
+ var data;
4458
+ return __generator(this, function (_a) {
4459
+ switch (_a.label) {
4460
+ case 0:
4461
+ if (!accountId || !id) {
4462
+ throw ("AccountID and ID are required.");
4463
+ }
4464
+ return [4 /*yield*/, api.GET("userGroup/" + accountId + "/" + id + "/users")];
4465
+ case 1:
4466
+ data = _a.sent();
4467
+ return [2 /*return*/, data.Items];
4468
+ }
4469
+ });
4470
+ });
4471
+ }
4472
+ UserGroup.GetUsers = GetUsers;
4473
+ function GetListByPerm(api, accountId, perm) {
4474
+ return __awaiter(this, void 0, void 0, function () {
4475
+ var data;
4476
+ return __generator(this, function (_a) {
4477
+ switch (_a.label) {
4478
+ case 0:
4479
+ if (!accountId || !perm) {
4480
+ throw ("AccountID and Perm are required.");
4481
+ }
4482
+ return [4 /*yield*/, api.GET("userGroupsByFeature/" + accountId + "/" + perm)];
4483
+ case 1:
4484
+ data = _a.sent();
4485
+ return [2 /*return*/, data.Items];
4486
+ }
4487
+ });
4488
+ });
4489
+ }
4490
+ UserGroup.GetListByPerm = GetListByPerm;
4491
+ function GetList(api, accountId) {
4492
+ return __awaiter(this, void 0, void 0, function () {
4493
+ var data;
4494
+ return __generator(this, function (_a) {
4495
+ switch (_a.label) {
4496
+ case 0:
4497
+ if (!accountId) {
4498
+ throw ("AccountID is required.");
4499
+ }
4500
+ return [4 /*yield*/, api.GET("userGroups/" + accountId)];
4501
+ case 1:
4502
+ data = _a.sent();
4503
+ return [2 /*return*/, data.Items];
4504
+ }
4505
+ });
4506
+ });
4507
+ }
4508
+ UserGroup.GetList = GetList;
4509
+ function Delete(api, accountId, id) {
4510
+ return __awaiter(this, void 0, void 0, function () {
4511
+ return __generator(this, function (_a) {
4512
+ if (!accountId || !id) {
4513
+ throw ("AccountID and ID are required.");
4514
+ }
4515
+ return [2 /*return*/, api.DELETE("account/" + accountId + "/userGroupID/" + id)];
4516
+ });
4517
+ });
4518
+ }
4519
+ UserGroup.Delete = Delete;
4520
+ function Update(api, data) {
4521
+ return __awaiter(this, void 0, void 0, function () {
4522
+ return __generator(this, function (_a) {
4523
+ switch (_a.label) {
4524
+ case 0:
4525
+ if (!data.Name || !data["ClientAccount.ID"]) {
4526
+ throw ("User group name and client account ID are required.");
4527
+ }
4528
+ return [4 /*yield*/, api.POST("userGroup" + (data.ID ? ("/" + data.ID) : ""), data)];
4529
+ case 1:
4530
+ data = _a.sent();
4531
+ return [2 /*return*/, data];
4532
+ }
4533
+ });
4534
+ });
4535
+ }
4536
+ UserGroup.Update = Update;
4537
+ })(UserGroup || (UserGroup = {}));
4538
+
4539
+ var User;
4540
+ (function (User) {
4541
+ function GetCacheKey(userId, accountId) {
4542
+ return Api.ECacheKey.User + Api.ECacheKey.Id + userId + Api.ECacheKey.Id + accountId;
4543
+ }
4544
+ User.GetCacheKey = GetCacheKey;
4545
+ var EType;
4546
+ (function (EType) {
4547
+ EType["User"] = "LOGIN_USER";
4548
+ EType["AccessToken"] = "ACCESS_TOKEN";
4549
+ })(EType = User.EType || (User.EType = {}));
4550
+ function Get(api, id, accountId) {
4551
+ return __awaiter(this, void 0, void 0, function () {
4552
+ var cacheData, req;
4553
+ return __generator(this, function (_a) {
4554
+ switch (_a.label) {
4555
+ case 0:
4556
+ if (!id) {
4557
+ throw ("ID is required.");
4558
+ }
4559
+ cacheData = api.Cache.Get(GetCacheKey(id, accountId));
4560
+ if (cacheData) {
4561
+ return [2 /*return*/, cacheData];
4562
+ }
4563
+ return [4 /*yield*/, api.GET("user/" + id)];
4564
+ case 1:
4565
+ req = _a.sent();
4566
+ api.Cache.Set(GetCacheKey(id, accountId), req, Api.DEFAULT_CACHE_DURATION);
4567
+ return [2 /*return*/, req];
4568
+ }
4569
+ });
4570
+ });
4571
+ }
4572
+ User.Get = Get;
4573
+ function Update(api, data) {
4574
+ return __awaiter(this, void 0, void 0, function () {
4575
+ return __generator(this, function (_a) {
4576
+ switch (_a.label) {
4577
+ case 0:
4578
+ if (!(data === null || data === void 0 ? void 0 : data.ID) || !(data === null || data === void 0 ? void 0 : data.Type)) {
4579
+ throw ("ID and Type are required.");
4580
+ }
4581
+ return [4 /*yield*/, api.POST("user/" + data.ID, data)];
4582
+ case 1:
4583
+ data = _a.sent();
4584
+ api.Cache.RemoveByContains(Api.ECacheKey.User + Api.ECacheKey.Id + data.ID);
4585
+ if (data.Type == EType.AccessToken) {
4586
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.AccessToken + Api.ECacheKey.Account);
4587
+ }
4588
+ else if (data.Type == EType.User) {
4589
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.User + Api.ECacheKey.Account);
4590
+ }
4591
+ return [2 /*return*/, data];
4592
+ }
4593
+ });
4594
+ });
4595
+ }
4596
+ User.Update = Update;
4597
+ var LoginUser;
4598
+ (function (LoginUser) {
4599
+ function GetListCacheKey(accountId) {
4600
+ return Api.ECacheKey.User + Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
4601
+ }
4602
+ LoginUser.GetListCacheKey = GetListCacheKey;
4603
+ function GetList(api, accountId, exclusive) {
4604
+ return __awaiter(this, void 0, void 0, function () {
4605
+ var cacheData, req;
4606
+ var _this = this;
4607
+ return __generator(this, function (_a) {
4608
+ if (!accountId) {
4609
+ throw ("Client account ID is required.");
4610
+ }
4611
+ if (!exclusive) {
4612
+ exclusive = false;
4613
+ }
4614
+ cacheData = exclusive ? null : api.Cache.Get(GetListCacheKey(accountId));
4615
+ if (cacheData) {
4616
+ return [2 /*return*/, cacheData];
4617
+ }
4618
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
4619
+ var data, e_1;
4620
+ return __generator(this, function (_a) {
4621
+ switch (_a.label) {
4622
+ case 0:
4623
+ _a.trys.push([0, 2, , 3]);
4624
+ return [4 /*yield*/, api.GET("users?clientAccountID=" + accountId + (exclusive ? "&allExcludingClientAccount=true" : ""))];
4625
+ case 1:
4626
+ data = _a.sent();
4627
+ res(data.Items);
4628
+ return [3 /*break*/, 3];
4629
+ case 2:
4630
+ e_1 = _a.sent();
4631
+ rej(e_1);
4632
+ return [3 /*break*/, 3];
4633
+ case 3: return [2 /*return*/];
4634
+ }
4635
+ });
4636
+ }); });
4637
+ req.then(function (users) {
4638
+ for (var i = 0; i < users.length; i++) {
4639
+ api.Cache.Set(GetCacheKey(users[i].ID, accountId), users[i]);
4640
+ }
4641
+ });
4642
+ if (!exclusive) {
4643
+ api.Cache.Set(GetListCacheKey(accountId), req, Api.DEFAULT_CACHE_DURATION);
4644
+ }
4645
+ return [2 /*return*/, req];
4646
+ });
4647
+ });
4648
+ }
4649
+ LoginUser.GetList = GetList;
4650
+ })(LoginUser = User.LoginUser || (User.LoginUser = {}));
4651
+ var AccessToken;
4652
+ (function (AccessToken) {
4653
+ function GetListCacheKey(accountId) {
4654
+ return Api.ECacheKey.AccessToken + Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
4655
+ }
4656
+ AccessToken.GetListCacheKey = GetListCacheKey;
4657
+ function GetList(api, accountId) {
4658
+ return __awaiter(this, void 0, void 0, function () {
4659
+ var cacheData, req;
4660
+ var _this = this;
4661
+ return __generator(this, function (_a) {
4662
+ cacheData = api.Cache.Get(GetListCacheKey(accountId));
4663
+ if (cacheData) {
4664
+ return [2 /*return*/, cacheData];
4665
+ }
4666
+ req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
4667
+ var data, e_2;
4668
+ return __generator(this, function (_a) {
4669
+ switch (_a.label) {
4670
+ case 0:
4671
+ _a.trys.push([0, 2, , 3]);
4672
+ return [4 /*yield*/, api.GET("usersByClientAccount/accessTokens")];
4673
+ case 1:
4674
+ data = _a.sent();
4675
+ res(data.Items);
4676
+ return [3 /*break*/, 3];
4677
+ case 2:
4678
+ e_2 = _a.sent();
4679
+ rej(e_2);
4680
+ return [3 /*break*/, 3];
4681
+ case 3: return [2 /*return*/];
4682
+ }
4683
+ });
4684
+ }); });
4685
+ req.then(function (users) {
4686
+ for (var i = 0; i < users.length; i++) {
4687
+ api.Cache.Set(GetCacheKey(users[i].ID, accountId), users[i]);
4688
+ }
4689
+ });
4690
+ api.Cache.Set(GetListCacheKey(accountId), req, Api.DEFAULT_CACHE_DURATION);
4691
+ return [2 /*return*/, req];
4692
+ });
4693
+ });
4694
+ }
4695
+ AccessToken.GetList = GetList;
4696
+ function Delete(api, id) {
4697
+ return __awaiter(this, void 0, void 0, function () {
4698
+ return __generator(this, function (_a) {
4699
+ switch (_a.label) {
4700
+ case 0: return [4 /*yield*/, api.DELETE("accessToken/" + id)];
4701
+ case 1:
4702
+ _a.sent();
4703
+ api.Cache.RemoveByContains(Api.ECacheKey.User + Api.ECacheKey.Id + id);
4704
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.AccessToken + Api.ECacheKey.Account);
4705
+ return [2 /*return*/];
4706
+ }
4707
+ });
4708
+ });
4709
+ }
4710
+ AccessToken.Delete = Delete;
4711
+ function Create(api, data) {
4712
+ return __awaiter(this, void 0, void 0, function () {
4713
+ return __generator(this, function (_a) {
4714
+ switch (_a.label) {
4715
+ case 0:
4716
+ if (!data) {
4717
+ data = {};
4718
+ }
4719
+ if (data.Type == EType.User) {
4720
+ throw ("User type is not allowed.");
4721
+ }
4722
+ if (!data.Type) {
4723
+ data.Type = EType.AccessToken;
4724
+ }
4725
+ return [4 /*yield*/, api.POST("accessToken", data)];
4726
+ case 1:
4727
+ data = _a.sent();
4728
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.AccessToken + Api.ECacheKey.Account);
4729
+ return [2 /*return*/, data];
4730
+ }
4731
+ });
4732
+ });
4733
+ }
4734
+ AccessToken.Create = Create;
4735
+ })(AccessToken = User.AccessToken || (User.AccessToken = {}));
4736
+ })(User || (User = {}));
4737
+
4738
+ var EncryptUtils;
4739
+ (function (EncryptUtils) {
4740
+ // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
4741
+ function Cyrb53Hash(str, seed) {
4742
+ if (seed === void 0) { seed = 0; }
4743
+ var h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
4744
+ for (var i = 0, ch = void 0; i < str.length; i++) {
4745
+ ch = str.charCodeAt(i);
4746
+ h1 = Math.imul(h1 ^ ch, 2654435761);
4747
+ h2 = Math.imul(h2 ^ ch, 1597334677);
4748
+ }
4749
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
4750
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
4751
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0));
4752
+ }
4753
+ EncryptUtils.Cyrb53Hash = Cyrb53Hash;
4754
+ })(EncryptUtils || (EncryptUtils = {}));
4755
+
4756
+ var MathUtils;
4757
+ (function (MathUtils) {
4758
+ function Round(num, decimals) {
4759
+ if (decimals === void 0) { decimals = 0; }
4760
+ if (decimals <= 0) {
4761
+ return Math.round(num);
4762
+ }
4763
+ var tmp = "1";
4764
+ for (var i = 0; i < decimals; i++) {
4765
+ tmp += "0";
4766
+ }
4767
+ var d = parseFloat(tmp);
4768
+ return Math.round((num + Number.EPSILON) * d) / d;
4769
+ }
4770
+ MathUtils.Round = Round;
4771
+ function RandInt(min, max) {
4772
+ if (min == max) {
4773
+ return min;
4774
+ }
4775
+ else if (min > max) {
4776
+ throw ("Min is greater than max.");
4777
+ }
4778
+ return Math.floor(Math.random() * (max - min + 1)) + min;
4779
+ }
4780
+ MathUtils.RandInt = RandInt;
4781
+ })(MathUtils || (MathUtils = {}));
4782
+
4783
+ export { AnnDocument, AbstractApi, Api, BruceApi, CamApi, IdmApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, EntityLoadedGetter, ClientFile, ProgramKey, MenuItemZoomControl, MenuItem, ProjectViewBookmark, ProjectView, PendingAction, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Ucs, Permission, Session, UserGroup, User, EncryptUtils, MathUtils, ObjectUtils, PathUtils };
4784
+ //# sourceMappingURL=bruce-models.es5.js.map