bruce-models 0.7.8 → 0.8.0

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.
Files changed (92) hide show
  1. package/dist/bruce-models.es5.js +167 -8
  2. package/dist/bruce-models.es5.js.map +1 -1
  3. package/dist/bruce-models.umd.js +165 -7
  4. package/dist/bruce-models.umd.js.map +1 -1
  5. package/dist/lib/account/account.js +244 -244
  6. package/dist/lib/ann-document/ann-document.js +116 -116
  7. package/dist/lib/api/abstract-api.js +269 -269
  8. package/dist/lib/api/api.js +85 -85
  9. package/dist/lib/api/bruce-api.js +243 -228
  10. package/dist/lib/api/bruce-api.js.map +1 -1
  11. package/dist/lib/api/cam-api.js +132 -132
  12. package/dist/lib/api/global-api.js +131 -131
  13. package/dist/lib/api/idm-api.js +132 -132
  14. package/dist/lib/bruce-models.js +85 -84
  15. package/dist/lib/bruce-models.js.map +1 -1
  16. package/dist/lib/calculator/calculator.js +159 -158
  17. package/dist/lib/calculator/calculator.js.map +1 -1
  18. package/dist/lib/client-file/client-file.js +188 -188
  19. package/dist/lib/common/bounds.js +2 -2
  20. package/dist/lib/common/bruce-event.js +48 -48
  21. package/dist/lib/common/bruce-variable.js +54 -54
  22. package/dist/lib/common/cache.js +86 -86
  23. package/dist/lib/common/camera.js +11 -11
  24. package/dist/lib/common/cartes.js +55 -55
  25. package/dist/lib/common/carto.js +60 -60
  26. package/dist/lib/common/color.js +86 -86
  27. package/dist/lib/common/delay-queue.js +60 -60
  28. package/dist/lib/common/dictionary.js +2 -2
  29. package/dist/lib/common/geometry.js +120 -120
  30. package/dist/lib/common/transform.js +2 -2
  31. package/dist/lib/common/utc.js +39 -39
  32. package/dist/lib/custom-form/custom-form.js +136 -136
  33. package/dist/lib/data-lab/data-lab.js +90 -90
  34. package/dist/lib/entity/entity-attachment-type.js +132 -132
  35. package/dist/lib/entity/entity-attachment.js +208 -208
  36. package/dist/lib/entity/entity-comment.js +132 -132
  37. package/dist/lib/entity/entity-coords.js +181 -181
  38. package/dist/lib/entity/entity-link.js +132 -132
  39. package/dist/lib/entity/entity-lod.js +189 -189
  40. package/dist/lib/entity/entity-relation-type.js +150 -150
  41. package/dist/lib/entity/entity-relation.js +189 -189
  42. package/dist/lib/entity/entity-source.js +176 -176
  43. package/dist/lib/entity/entity-tag.js +229 -229
  44. package/dist/lib/entity/entity-type.js +163 -163
  45. package/dist/lib/entity/entity.js +358 -358
  46. package/dist/lib/entity/getters/batched-data-getter.js +91 -91
  47. package/dist/lib/entity/getters/entity-filter-getter.js +344 -344
  48. package/dist/lib/entity/getters/entity-globe.js +135 -135
  49. package/dist/lib/entity/getters/view-monitor.js +2 -2
  50. package/dist/lib/import/import-cad.js +82 -82
  51. package/dist/lib/import/import-csv.js +51 -51
  52. package/dist/lib/import/import-json.js +51 -51
  53. package/dist/lib/import/import-kml.js +51 -51
  54. package/dist/lib/import/imported-file.js +121 -121
  55. package/dist/lib/import/imported-file.js.map +1 -1
  56. package/dist/lib/markup/markup.js +40 -40
  57. package/dist/lib/program-key/program-key.js +152 -152
  58. package/dist/lib/project/menu-item.js +115 -115
  59. package/dist/lib/project/project-view-bookmark.js +183 -183
  60. package/dist/lib/project/project-view-legacy-tile.js +115 -115
  61. package/dist/lib/project/project-view-tile.js +119 -119
  62. package/dist/lib/project/project-view-tile.js.map +1 -1
  63. package/dist/lib/project/project-view.js +177 -177
  64. package/dist/lib/project/zoom-control.js +17 -17
  65. package/dist/lib/server/message-broker.js +159 -0
  66. package/dist/lib/server/message-broker.js.map +1 -0
  67. package/dist/lib/server/pending-action.js +106 -106
  68. package/dist/lib/server/task.js +113 -113
  69. package/dist/lib/style/style.js +152 -152
  70. package/dist/lib/tileset/tileset-cad.js +2 -2
  71. package/dist/lib/tileset/tileset-entities-map-tiles.js +18 -18
  72. package/dist/lib/tileset/tileset-entities.js +2 -2
  73. package/dist/lib/tileset/tileset-ext-map-tiles.js +17 -17
  74. package/dist/lib/tileset/tileset-ext-terrain-tiles.js +2 -2
  75. package/dist/lib/tileset/tileset-map-tiles.js +2 -2
  76. package/dist/lib/tileset/tileset-pointcloud.js +2 -2
  77. package/dist/lib/tileset/tileset-terrain-tiles.js +2 -2
  78. package/dist/lib/tileset/tileset.js +403 -403
  79. package/dist/lib/user/permission.js +20 -20
  80. package/dist/lib/user/session.js +160 -160
  81. package/dist/lib/user/user-group.js +139 -139
  82. package/dist/lib/user/user.js +451 -451
  83. package/dist/lib/util/encrypt-utils.js +20 -20
  84. package/dist/lib/util/math-utils.js +41 -41
  85. package/dist/lib/util/object-utils.js +17 -17
  86. package/dist/lib/util/path-utils.js +61 -61
  87. package/dist/lib/util/url-utils.js +107 -107
  88. package/dist/types/api/bruce-api.d.ts +9 -1
  89. package/dist/types/bruce-models.d.ts +1 -0
  90. package/dist/types/project/project-view-tile.d.ts +2 -6
  91. package/dist/types/server/message-broker.d.ts +108 -0
  92. package/package.json +1 -1
@@ -1,359 +1,359 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Entity = void 0;
51
- var api_1 = require("../api/api");
52
- var object_utils_1 = require("../util/object-utils");
53
- var path_utils_1 = require("../util/path-utils");
54
- /**
55
- * Describes the "Entity" concept within Bruce.
56
- * An entity is a JSON blob containing both internal data and user-defined data.
57
- * Entity records have many thinks linked to them through their UIDs such as links, files and relationships.
58
- */
59
- var Entity;
60
- (function (Entity) {
61
- function GetCacheKey(entityId) {
62
- return "" + api_1.Api.ECacheKey.Entity + api_1.Api.ECacheKey.Id + entityId;
63
- }
64
- Entity.GetCacheKey = GetCacheKey;
65
- function Get(api, entityId) {
66
- return __awaiter(this, void 0, void 0, function () {
67
- var key, cacheData, req;
68
- return __generator(this, function (_a) {
69
- if (!entityId) {
70
- throw ("Entity ID is required.");
71
- }
72
- key = GetCacheKey(entityId);
73
- cacheData = api.Cache.Get(key);
74
- if (cacheData) {
75
- return [2 /*return*/, cacheData];
76
- }
77
- req = api.GET("entity/" + entityId, api_1.Api.PrepReqParams());
78
- api.Cache.Set(key, req, api_1.Api.DEFAULT_CACHE_DURATION);
79
- return [2 /*return*/, req];
80
- });
81
- });
82
- }
83
- Entity.Get = Get;
84
- function GetListByIds(api, entityIds) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var reqs, reqIds, i, entityId, key, cacheData, reqData, req_1, _loop_1, i;
87
- var _this = this;
88
- return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0:
91
- if (!entityIds.length) {
92
- throw ("Entity IDs are required.");
93
- }
94
- reqs = [];
95
- reqIds = [];
96
- for (i = 0; i < entityIds.length; i++) {
97
- entityId = entityIds[i];
98
- key = GetCacheKey(entityId);
99
- cacheData = api.Cache.Get(key);
100
- if (cacheData) {
101
- reqs.push(cacheData);
102
- }
103
- else {
104
- reqIds.push(entityId);
105
- }
106
- }
107
- reqData = {
108
- Filter: {
109
- ID: {
110
- in: reqIds
111
- }
112
- },
113
- PageSize: reqIds.length
114
- };
115
- if (reqIds.length > 0) {
116
- req_1 = api.POST("entities", reqData, api_1.Api.PrepReqParams());
117
- _loop_1 = function (i) {
118
- var entityId = reqIds[i];
119
- var key = GetCacheKey(entityId);
120
- var prom = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
121
- var data, item, e_1;
122
- return __generator(this, function (_a) {
123
- switch (_a.label) {
124
- case 0:
125
- _a.trys.push([0, 2, , 3]);
126
- return [4 /*yield*/, req_1];
127
- case 1:
128
- data = _a.sent();
129
- item = data.Items.find(function (x) { return x.Bruce.ID == entityId; });
130
- res(item);
131
- return [3 /*break*/, 3];
132
- case 2:
133
- e_1 = _a.sent();
134
- return [3 /*break*/, 3];
135
- case 3:
136
- res(null);
137
- return [2 /*return*/];
138
- }
139
- });
140
- }); });
141
- api.Cache.Set(key, prom, api_1.Api.DEFAULT_CACHE_DURATION);
142
- reqs.push(prom);
143
- };
144
- for (i = 0; i < reqIds.length; i++) {
145
- _loop_1(i);
146
- }
147
- }
148
- return [4 /*yield*/, Promise.all(reqs)];
149
- case 1: return [2 /*return*/, (_a.sent()).filter(function (x) { return !!x; })];
150
- }
151
- });
152
- });
153
- }
154
- Entity.GetListByIds = GetListByIds;
155
- function Delete(api, entityId) {
156
- return __awaiter(this, void 0, void 0, function () {
157
- return __generator(this, function (_a) {
158
- switch (_a.label) {
159
- case 0:
160
- if (!entityId) {
161
- throw ("Entity ID is required.");
162
- }
163
- return [4 /*yield*/, api.DELETE("entity/" + entityId, api_1.Api.PrepReqParams())];
164
- case 1:
165
- _a.sent();
166
- api.Cache.Remove(GetCacheKey(entityId));
167
- return [2 /*return*/];
168
- }
169
- });
170
- });
171
- }
172
- Entity.Delete = Delete;
173
- function DeleteList(api, entityIds) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- var i, entityId;
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0:
179
- if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
180
- throw ("Entity IDs are required.");
181
- }
182
- return [4 /*yield*/, api.POST("deleteEntities", {
183
- Items: entityIds
184
- }, api_1.Api.PrepReqParams())];
185
- case 1:
186
- _a.sent();
187
- for (i = 0; i < entityIds.length; i++) {
188
- entityId = entityIds[i];
189
- api.Cache.Remove(GetCacheKey(entityId));
190
- }
191
- return [2 /*return*/];
192
- }
193
- });
194
- });
195
- }
196
- Entity.DeleteList = DeleteList;
197
- function Update(api, data, override) {
198
- var _a, _b;
199
- return __awaiter(this, void 0, void 0, function () {
200
- var reqUrl;
201
- return __generator(this, function (_c) {
202
- switch (_c.label) {
203
- case 0:
204
- if (!((_a = data === null || data === void 0 ? void 0 : data.Bruce) === null || _a === void 0 ? void 0 : _a["EntityType.ID"])) {
205
- throw ("Entity Type ID is required.");
206
- }
207
- if (!((_b = data === null || data === void 0 ? void 0 : data.Bruce) === null || _b === void 0 ? void 0 : _b.ID)) {
208
- data.Bruce = __assign(__assign({}, data.Bruce), { ID: object_utils_1.ObjectUtils.UId() });
209
- }
210
- reqUrl = "entity/" + data.Bruce.ID + "/?dataoverride=" + override + "&BruceEntityType=" + data.Bruce["EntityType.ID"];
211
- return [4 /*yield*/, api.POST(reqUrl, data, api_1.Api.PrepReqParams())];
212
- case 1:
213
- data = _c.sent();
214
- api.Cache.Remove(GetCacheKey(data.Bruce.ID));
215
- return [2 /*return*/, data];
216
- }
217
- });
218
- });
219
- }
220
- Entity.Update = Update;
221
- function RemoveTag(data, tagId) {
222
- var _a;
223
- var tags = (_a = data.Bruce["Layer.ID"]) !== null && _a !== void 0 ? _a : [];
224
- var index = tags.indexOf(tagId);
225
- if (index >= 0) {
226
- tags.splice(index, 1);
227
- data.Bruce["Layer.ID"] = tags;
228
- }
229
- }
230
- Entity.RemoveTag = RemoveTag;
231
- function AddTag(data, tagId) {
232
- var _a;
233
- var tags = (_a = data.Bruce["Layer.ID"]) !== null && _a !== void 0 ? _a : [];
234
- if (!tags.includes(tagId)) {
235
- tags.push(tagId);
236
- data.Bruce["Layer.ID"] = tags;
237
- }
238
- }
239
- Entity.AddTag = AddTag;
240
- function SetValue(data, path, value) {
241
- var curData = data;
242
- for (var i = 0; i < path.length; i++) {
243
- var step = path[i];
244
- if (!curData[step] || typeof curData[step] != "object") {
245
- curData[step] = {};
246
- }
247
- if (i >= path.length - 1) {
248
- curData[step] = value;
249
- break;
250
- }
251
- curData = curData[step];
252
- }
253
- }
254
- Entity.SetValue = SetValue;
255
- function GetValue(data, path) {
256
- var curData = data;
257
- for (var i = 0; i < path.length; i++) {
258
- var step = path[i];
259
- if (!curData[step]) {
260
- return null;
261
- }
262
- if (i >= path.length - 1) {
263
- return curData[step];
264
- }
265
- curData = curData[step];
266
- }
267
- return null;
268
- }
269
- Entity.GetValue = GetValue;
270
- /**
271
- * Calculates an entity's name based on attribute priority set in the type.
272
- * @param entity
273
- * @param type
274
- * @param defaultToId
275
- * If true, will return the entity ID if no name can be calculated.
276
- * Otherwise it returns null.
277
- * @returns
278
- */
279
- function CalculateName(entity, type, defaultToId) {
280
- var attrStr = type.DisplayNameAttributePath;
281
- if (attrStr) {
282
- var attrPaths = attrStr.split(",");
283
- for (var i = 0; i < attrPaths.length; i++) {
284
- var pathStr = attrPaths[i];
285
- var path = path_utils_1.PathUtils.Parse(pathStr);
286
- var name_1 = Entity.GetValue(entity, path);
287
- if (name_1) {
288
- return name_1;
289
- }
290
- }
291
- }
292
- return defaultToId ? entity.Bruce.ID : null;
293
- }
294
- Entity.CalculateName = CalculateName;
295
- var Filter;
296
- (function (Filter) {
297
- var V1;
298
- (function (V1) {
299
- function GetList(api, filter) {
300
- return __awaiter(this, void 0, void 0, function () {
301
- var requestFilter, url, data, entities, i, entity, id;
302
- return __generator(this, function (_a) {
303
- switch (_a.label) {
304
- case 0:
305
- if (!(filter === null || filter === void 0 ? void 0 : filter.entityTypeId)) {
306
- throw ("Entity Type ID is required.");
307
- }
308
- requestFilter = {};
309
- if (filter.entityTypeConditions) {
310
- requestFilter = __assign({}, filter.entityTypeConditions);
311
- }
312
- if (filter.layerIds != null && filter.layerIds.length > 0) {
313
- requestFilter["Bruce.Layer.ID"] = {
314
- equals: filter.layerIds
315
- };
316
- }
317
- if (filter.bounds) {
318
- requestFilter["geometry"] = {
319
- "intersects": [
320
- filter.bounds.south,
321
- filter.bounds.north,
322
- filter.bounds.west,
323
- filter.bounds.east
324
- ]
325
- };
326
- }
327
- url = "entities" +
328
- (
329
- // Page size and index.
330
- "?PageSize=" + filter.pageSize + "&PageIndex=" + filter.pageIndex) +
331
- // Entity type id.
332
- (filter.entityTypeId ? "&BruceEntityType=" + filter.entityTypeId : "") +
333
- // Lod.
334
- (filter.lodCategoryId ? "&LODType=" + filter.lodCategoryId : "") +
335
- // Attribute filter.
336
- (!requestFilter ? "" : "&Filter=" + api_1.Api.Encode(JSON.stringify(requestFilter))) +
337
- // Order by attribute + sort order.
338
- (!filter.orderBy ? "" : "&OrderBy=" + filter.orderBy) +
339
- (filter.sortOrder ? "&SortOrder=" + (filter.sortOrder == api_1.Api.ESortOrder.Asc ? "ASC" : "DESC") : "");
340
- return [4 /*yield*/, api.GET(url, api_1.Api.PrepReqParams())];
341
- case 1:
342
- data = _a.sent();
343
- entities = data.Items;
344
- for (i = 0; i < entities.length; i++) {
345
- entity = entities[i];
346
- id = entity.Bruce.ID;
347
- api.Cache.Set(GetCacheKey(id), entity, api_1.Api.DEFAULT_CACHE_DURATION);
348
- }
349
- return [2 /*return*/, entities];
350
- }
351
- });
352
- });
353
- }
354
- V1.GetList = GetList;
355
- })(V1 = Filter.V1 || (Filter.V1 = {}));
356
- // TODO: Helpers for constructing the filter.
357
- })(Filter = Entity.Filter || (Entity.Filter = {}));
358
- })(Entity = exports.Entity || (exports.Entity = {}));
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Entity = void 0;
51
+ var api_1 = require("../api/api");
52
+ var object_utils_1 = require("../util/object-utils");
53
+ var path_utils_1 = require("../util/path-utils");
54
+ /**
55
+ * Describes the "Entity" concept within Bruce.
56
+ * An entity is a JSON blob containing both internal data and user-defined data.
57
+ * Entity records have many thinks linked to them through their UIDs such as links, files and relationships.
58
+ */
59
+ var Entity;
60
+ (function (Entity) {
61
+ function GetCacheKey(entityId) {
62
+ return "" + api_1.Api.ECacheKey.Entity + api_1.Api.ECacheKey.Id + entityId;
63
+ }
64
+ Entity.GetCacheKey = GetCacheKey;
65
+ function Get(api, entityId) {
66
+ return __awaiter(this, void 0, void 0, function () {
67
+ var key, cacheData, req;
68
+ return __generator(this, function (_a) {
69
+ if (!entityId) {
70
+ throw ("Entity ID is required.");
71
+ }
72
+ key = GetCacheKey(entityId);
73
+ cacheData = api.Cache.Get(key);
74
+ if (cacheData) {
75
+ return [2 /*return*/, cacheData];
76
+ }
77
+ req = api.GET("entity/" + entityId, api_1.Api.PrepReqParams());
78
+ api.Cache.Set(key, req, api_1.Api.DEFAULT_CACHE_DURATION);
79
+ return [2 /*return*/, req];
80
+ });
81
+ });
82
+ }
83
+ Entity.Get = Get;
84
+ function GetListByIds(api, entityIds) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var reqs, reqIds, i, entityId, key, cacheData, reqData, req_1, _loop_1, i;
87
+ var _this = this;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ if (!entityIds.length) {
92
+ throw ("Entity IDs are required.");
93
+ }
94
+ reqs = [];
95
+ reqIds = [];
96
+ for (i = 0; i < entityIds.length; i++) {
97
+ entityId = entityIds[i];
98
+ key = GetCacheKey(entityId);
99
+ cacheData = api.Cache.Get(key);
100
+ if (cacheData) {
101
+ reqs.push(cacheData);
102
+ }
103
+ else {
104
+ reqIds.push(entityId);
105
+ }
106
+ }
107
+ reqData = {
108
+ Filter: {
109
+ ID: {
110
+ in: reqIds
111
+ }
112
+ },
113
+ PageSize: reqIds.length
114
+ };
115
+ if (reqIds.length > 0) {
116
+ req_1 = api.POST("entities", reqData, api_1.Api.PrepReqParams());
117
+ _loop_1 = function (i) {
118
+ var entityId = reqIds[i];
119
+ var key = GetCacheKey(entityId);
120
+ var prom = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
121
+ var data, item, e_1;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0:
125
+ _a.trys.push([0, 2, , 3]);
126
+ return [4 /*yield*/, req_1];
127
+ case 1:
128
+ data = _a.sent();
129
+ item = data.Items.find(function (x) { return x.Bruce.ID == entityId; });
130
+ res(item);
131
+ return [3 /*break*/, 3];
132
+ case 2:
133
+ e_1 = _a.sent();
134
+ return [3 /*break*/, 3];
135
+ case 3:
136
+ res(null);
137
+ return [2 /*return*/];
138
+ }
139
+ });
140
+ }); });
141
+ api.Cache.Set(key, prom, api_1.Api.DEFAULT_CACHE_DURATION);
142
+ reqs.push(prom);
143
+ };
144
+ for (i = 0; i < reqIds.length; i++) {
145
+ _loop_1(i);
146
+ }
147
+ }
148
+ return [4 /*yield*/, Promise.all(reqs)];
149
+ case 1: return [2 /*return*/, (_a.sent()).filter(function (x) { return !!x; })];
150
+ }
151
+ });
152
+ });
153
+ }
154
+ Entity.GetListByIds = GetListByIds;
155
+ function Delete(api, entityId) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ return __generator(this, function (_a) {
158
+ switch (_a.label) {
159
+ case 0:
160
+ if (!entityId) {
161
+ throw ("Entity ID is required.");
162
+ }
163
+ return [4 /*yield*/, api.DELETE("entity/" + entityId, api_1.Api.PrepReqParams())];
164
+ case 1:
165
+ _a.sent();
166
+ api.Cache.Remove(GetCacheKey(entityId));
167
+ return [2 /*return*/];
168
+ }
169
+ });
170
+ });
171
+ }
172
+ Entity.Delete = Delete;
173
+ function DeleteList(api, entityIds) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var i, entityId;
176
+ return __generator(this, function (_a) {
177
+ switch (_a.label) {
178
+ case 0:
179
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
180
+ throw ("Entity IDs are required.");
181
+ }
182
+ return [4 /*yield*/, api.POST("deleteEntities", {
183
+ Items: entityIds
184
+ }, api_1.Api.PrepReqParams())];
185
+ case 1:
186
+ _a.sent();
187
+ for (i = 0; i < entityIds.length; i++) {
188
+ entityId = entityIds[i];
189
+ api.Cache.Remove(GetCacheKey(entityId));
190
+ }
191
+ return [2 /*return*/];
192
+ }
193
+ });
194
+ });
195
+ }
196
+ Entity.DeleteList = DeleteList;
197
+ function Update(api, data, override) {
198
+ var _a, _b;
199
+ return __awaiter(this, void 0, void 0, function () {
200
+ var reqUrl;
201
+ return __generator(this, function (_c) {
202
+ switch (_c.label) {
203
+ case 0:
204
+ if (!((_a = data === null || data === void 0 ? void 0 : data.Bruce) === null || _a === void 0 ? void 0 : _a["EntityType.ID"])) {
205
+ throw ("Entity Type ID is required.");
206
+ }
207
+ if (!((_b = data === null || data === void 0 ? void 0 : data.Bruce) === null || _b === void 0 ? void 0 : _b.ID)) {
208
+ data.Bruce = __assign(__assign({}, data.Bruce), { ID: object_utils_1.ObjectUtils.UId() });
209
+ }
210
+ reqUrl = "entity/" + data.Bruce.ID + "/?dataoverride=" + override + "&BruceEntityType=" + data.Bruce["EntityType.ID"];
211
+ return [4 /*yield*/, api.POST(reqUrl, data, api_1.Api.PrepReqParams())];
212
+ case 1:
213
+ data = _c.sent();
214
+ api.Cache.Remove(GetCacheKey(data.Bruce.ID));
215
+ return [2 /*return*/, data];
216
+ }
217
+ });
218
+ });
219
+ }
220
+ Entity.Update = Update;
221
+ function RemoveTag(data, tagId) {
222
+ var _a;
223
+ var tags = (_a = data.Bruce["Layer.ID"]) !== null && _a !== void 0 ? _a : [];
224
+ var index = tags.indexOf(tagId);
225
+ if (index >= 0) {
226
+ tags.splice(index, 1);
227
+ data.Bruce["Layer.ID"] = tags;
228
+ }
229
+ }
230
+ Entity.RemoveTag = RemoveTag;
231
+ function AddTag(data, tagId) {
232
+ var _a;
233
+ var tags = (_a = data.Bruce["Layer.ID"]) !== null && _a !== void 0 ? _a : [];
234
+ if (!tags.includes(tagId)) {
235
+ tags.push(tagId);
236
+ data.Bruce["Layer.ID"] = tags;
237
+ }
238
+ }
239
+ Entity.AddTag = AddTag;
240
+ function SetValue(data, path, value) {
241
+ var curData = data;
242
+ for (var i = 0; i < path.length; i++) {
243
+ var step = path[i];
244
+ if (!curData[step] || typeof curData[step] != "object") {
245
+ curData[step] = {};
246
+ }
247
+ if (i >= path.length - 1) {
248
+ curData[step] = value;
249
+ break;
250
+ }
251
+ curData = curData[step];
252
+ }
253
+ }
254
+ Entity.SetValue = SetValue;
255
+ function GetValue(data, path) {
256
+ var curData = data;
257
+ for (var i = 0; i < path.length; i++) {
258
+ var step = path[i];
259
+ if (!curData[step]) {
260
+ return null;
261
+ }
262
+ if (i >= path.length - 1) {
263
+ return curData[step];
264
+ }
265
+ curData = curData[step];
266
+ }
267
+ return null;
268
+ }
269
+ Entity.GetValue = GetValue;
270
+ /**
271
+ * Calculates an entity's name based on attribute priority set in the type.
272
+ * @param entity
273
+ * @param type
274
+ * @param defaultToId
275
+ * If true, will return the entity ID if no name can be calculated.
276
+ * Otherwise it returns null.
277
+ * @returns
278
+ */
279
+ function CalculateName(entity, type, defaultToId) {
280
+ var attrStr = type.DisplayNameAttributePath;
281
+ if (attrStr) {
282
+ var attrPaths = attrStr.split(",");
283
+ for (var i = 0; i < attrPaths.length; i++) {
284
+ var pathStr = attrPaths[i];
285
+ var path = path_utils_1.PathUtils.Parse(pathStr);
286
+ var name_1 = Entity.GetValue(entity, path);
287
+ if (name_1) {
288
+ return name_1;
289
+ }
290
+ }
291
+ }
292
+ return defaultToId ? entity.Bruce.ID : null;
293
+ }
294
+ Entity.CalculateName = CalculateName;
295
+ var Filter;
296
+ (function (Filter) {
297
+ var V1;
298
+ (function (V1) {
299
+ function GetList(api, filter) {
300
+ return __awaiter(this, void 0, void 0, function () {
301
+ var requestFilter, url, data, entities, i, entity, id;
302
+ return __generator(this, function (_a) {
303
+ switch (_a.label) {
304
+ case 0:
305
+ if (!(filter === null || filter === void 0 ? void 0 : filter.entityTypeId)) {
306
+ throw ("Entity Type ID is required.");
307
+ }
308
+ requestFilter = {};
309
+ if (filter.entityTypeConditions) {
310
+ requestFilter = __assign({}, filter.entityTypeConditions);
311
+ }
312
+ if (filter.layerIds != null && filter.layerIds.length > 0) {
313
+ requestFilter["Bruce.Layer.ID"] = {
314
+ equals: filter.layerIds
315
+ };
316
+ }
317
+ if (filter.bounds) {
318
+ requestFilter["geometry"] = {
319
+ "intersects": [
320
+ filter.bounds.south,
321
+ filter.bounds.north,
322
+ filter.bounds.west,
323
+ filter.bounds.east
324
+ ]
325
+ };
326
+ }
327
+ url = "entities" +
328
+ (
329
+ // Page size and index.
330
+ "?PageSize=" + filter.pageSize + "&PageIndex=" + filter.pageIndex) +
331
+ // Entity type id.
332
+ (filter.entityTypeId ? "&BruceEntityType=" + filter.entityTypeId : "") +
333
+ // Lod.
334
+ (filter.lodCategoryId ? "&LODType=" + filter.lodCategoryId : "") +
335
+ // Attribute filter.
336
+ (!requestFilter ? "" : "&Filter=" + api_1.Api.Encode(JSON.stringify(requestFilter))) +
337
+ // Order by attribute + sort order.
338
+ (!filter.orderBy ? "" : "&OrderBy=" + filter.orderBy) +
339
+ (filter.sortOrder ? "&SortOrder=" + (filter.sortOrder == api_1.Api.ESortOrder.Asc ? "ASC" : "DESC") : "");
340
+ return [4 /*yield*/, api.GET(url, api_1.Api.PrepReqParams())];
341
+ case 1:
342
+ data = _a.sent();
343
+ entities = data.Items;
344
+ for (i = 0; i < entities.length; i++) {
345
+ entity = entities[i];
346
+ id = entity.Bruce.ID;
347
+ api.Cache.Set(GetCacheKey(id), entity, api_1.Api.DEFAULT_CACHE_DURATION);
348
+ }
349
+ return [2 /*return*/, entities];
350
+ }
351
+ });
352
+ });
353
+ }
354
+ V1.GetList = GetList;
355
+ })(V1 = Filter.V1 || (Filter.V1 = {}));
356
+ // TODO: Helpers for constructing the filter.
357
+ })(Filter = Entity.Filter || (Entity.Filter = {}));
358
+ })(Entity = exports.Entity || (exports.Entity = {}));
359
359
  //# sourceMappingURL=entity.js.map