bruce-models 1.9.7 → 1.9.8

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 (83) hide show
  1. package/dist/bruce-models.es5.js +9 -3
  2. package/dist/bruce-models.es5.js.map +1 -1
  3. package/dist/bruce-models.umd.js +9 -3
  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 +185 -185
  7. package/dist/lib/ann-document/ann-document.js +86 -86
  8. package/dist/lib/api/abstract-api.js +246 -246
  9. package/dist/lib/api/api-getters.js +134 -134
  10. package/dist/lib/api/api.js +93 -93
  11. package/dist/lib/api/bruce-api.js +216 -216
  12. package/dist/lib/api/cam-api.js +82 -82
  13. package/dist/lib/api/global-api.js +81 -81
  14. package/dist/lib/api/idm-api.js +82 -82
  15. package/dist/lib/bruce-models.js +86 -86
  16. package/dist/lib/calculator/calculator.js +341 -335
  17. package/dist/lib/calculator/calculator.js.map +1 -1
  18. package/dist/lib/client-file/client-file.js +245 -245
  19. package/dist/lib/common/bounds.js +61 -61
  20. package/dist/lib/common/bruce-event.js +46 -46
  21. package/dist/lib/common/bruce-variable.js +60 -60
  22. package/dist/lib/common/cache.js +165 -165
  23. package/dist/lib/common/camera.js +11 -11
  24. package/dist/lib/common/cartes.js +123 -123
  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 +56 -56
  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-content.js +26 -26
  33. package/dist/lib/custom-form/custom-form.js +106 -106
  34. package/dist/lib/data-lab/data-lab.js +49 -49
  35. package/dist/lib/entity/entity-attachment-type.js +83 -83
  36. package/dist/lib/entity/entity-attachment.js +122 -122
  37. package/dist/lib/entity/entity-attribute.js +29 -29
  38. package/dist/lib/entity/entity-comment.js +82 -82
  39. package/dist/lib/entity/entity-coords.js +149 -149
  40. package/dist/lib/entity/entity-link.js +82 -82
  41. package/dist/lib/entity/entity-lod-category.js +100 -100
  42. package/dist/lib/entity/entity-lod.js +185 -185
  43. package/dist/lib/entity/entity-relation-type.js +109 -109
  44. package/dist/lib/entity/entity-relation.js +132 -132
  45. package/dist/lib/entity/entity-source.js +136 -136
  46. package/dist/lib/entity/entity-tag.js +149 -149
  47. package/dist/lib/entity/entity-type-visual-settings.js +13 -13
  48. package/dist/lib/entity/entity-type.js +113 -113
  49. package/dist/lib/entity/entity.js +319 -319
  50. package/dist/lib/entity/getters/batched-data-getter.js +84 -84
  51. package/dist/lib/entity/getters/entity-filter-getter.js +303 -303
  52. package/dist/lib/entity/getters/entity-globe.js +211 -211
  53. package/dist/lib/entity/getters/view-monitor.js +2 -2
  54. package/dist/lib/import/import-cad.js +53 -53
  55. package/dist/lib/import/import-csv.js +23 -23
  56. package/dist/lib/import/import-json.js +23 -23
  57. package/dist/lib/import/import-kml.js +23 -23
  58. package/dist/lib/import/imported-file.js +91 -91
  59. package/dist/lib/internal/uploader.js +76 -76
  60. package/dist/lib/markup/markup.js +185 -185
  61. package/dist/lib/plugin/plugin.js +83 -83
  62. package/dist/lib/program-key/program-key.js +111 -111
  63. package/dist/lib/project/menu-item.js +121 -121
  64. package/dist/lib/project/project-view-bookmark.js +147 -147
  65. package/dist/lib/project/project-view-legacy-tile.js +77 -77
  66. package/dist/lib/project/project-view-tile.js +125 -125
  67. package/dist/lib/project/project-view.js +133 -133
  68. package/dist/lib/project/zoom-control.js +17 -17
  69. package/dist/lib/server/message-broker.js +142 -142
  70. package/dist/lib/server/pending-action.js +71 -71
  71. package/dist/lib/server/task.js +63 -63
  72. package/dist/lib/style/style.js +117 -117
  73. package/dist/lib/tileset/tileset.js +415 -415
  74. package/dist/lib/user/permission.js +20 -20
  75. package/dist/lib/user/session.js +137 -137
  76. package/dist/lib/user/user-group.js +94 -94
  77. package/dist/lib/user/user.js +446 -446
  78. package/dist/lib/util/encrypt-utils.js +19 -19
  79. package/dist/lib/util/math-utils.js +40 -40
  80. package/dist/lib/util/object-utils.js +17 -17
  81. package/dist/lib/util/path-utils.js +61 -61
  82. package/dist/lib/util/url-utils.js +94 -94
  83. package/package.json +1 -1
@@ -1,320 +1,320 @@
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.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 = {}));
320
320
  //# sourceMappingURL=entity.js.map