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