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