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
@@ -902,6 +902,149 @@
902
902
  CamApi.Api = Api$$1;
903
903
  })(exports.CamApi || (exports.CamApi = {}));
904
904
 
905
+ (function (MessageBroker) {
906
+ var Action;
907
+ (function (Action) {
908
+ Action["SUBSCRIBE"] = "subscribe";
909
+ Action["SUBSCRIBE_SHADOW"] = "subscribeShadow";
910
+ Action["UNSUBSCRIBE"] = "unsubscribe";
911
+ Action["BROADCAST"] = "broadcast";
912
+ Action["GET_TOPIC_SUBSCRIBERS"] = "getTopicSubscribers"; // requests topic subscribers without subscribing
913
+ })(Action = MessageBroker.Action || (MessageBroker.Action = {}));
914
+ /** Events types any component may get from server */
915
+ var Event;
916
+ (function (Event) {
917
+ Event["SAVED"] = "saved";
918
+ Event["UPDATED"] = "updated";
919
+ Event["DELETED"] = "deleted";
920
+ Event["EDIT_STARTED"] = "editStarted";
921
+ Event["EDIT_FINISHED"] = "editFinished";
922
+ Event["USERS_UPDATE"] = "usersUpdate";
923
+ })(Event = MessageBroker.Event || (MessageBroker.Event = {}));
924
+ /** Communicates with a server message broker */
925
+ var WebSocketBroker = /** @class */ (function () {
926
+ function WebSocketBroker(uri, env) {
927
+ this.uri = uri;
928
+ this.env = env;
929
+ this.subscriptions = new Map();
930
+ this.reconnects = 0;
931
+ this.maxReconnects = 5;
932
+ this.connect();
933
+ }
934
+ WebSocketBroker.prototype.connect = function () {
935
+ try {
936
+ this.ws = new WebSocket(this.formatApiUri(this.uri));
937
+ this.ws.onopen = this.onOpen.bind(this);
938
+ this.ws.onmessage = this.onMessage.bind(this);
939
+ this.ws.onerror = this.onError.bind(this);
940
+ this.ws.onclose = this.onClose.bind(this);
941
+ }
942
+ catch (e) {
943
+ console.error(e);
944
+ }
945
+ };
946
+ WebSocketBroker.prototype.formatApiUri = function (uri) {
947
+ var ws = document.location.protocol === "https:" ? "wss" : "ws";
948
+ return uri.replace(/^(https|http)/, ws) + "websocket";
949
+ };
950
+ WebSocketBroker.prototype.setUser = function (user) {
951
+ this.user = this.user ? this.user : user;
952
+ };
953
+ WebSocketBroker.prototype.onOpen = function (ev) {
954
+ if (this.env === exports.Api.EEnv.DEV) {
955
+ console.log("MessageBroker connection opened: ", ev);
956
+ }
957
+ };
958
+ WebSocketBroker.prototype.onClose = function (ev) {
959
+ var _this = this;
960
+ if (this.env === exports.Api.EEnv.DEV) {
961
+ console.log("MessageBroker connection closed, trying to reconnect: ", ev);
962
+ }
963
+ if (this.reconnects < this.maxReconnects) {
964
+ this.reconnects += 1;
965
+ setTimeout(function () { return _this.connect(); }, 5000 * this.reconnects);
966
+ }
967
+ };
968
+ WebSocketBroker.prototype.onMessage = function (ev) {
969
+ var _a;
970
+ var data = JSON.parse(ev.data);
971
+ (_a = this.subscriptions.get(data.topic)) === null || _a === void 0 ? void 0 : _a.forEach(function (cb) { return cb(data); });
972
+ };
973
+ WebSocketBroker.prototype.onError = function (ev) {
974
+ console.error("MessageBroker connection error: ", ev);
975
+ };
976
+ WebSocketBroker.prototype.addSubscriber = function (topic, callback) {
977
+ var subscribers = this.subscriptions.get(topic) || [];
978
+ if (subscribers.includes(callback)) {
979
+ return;
980
+ }
981
+ subscribers.push(callback);
982
+ this.subscriptions.set(topic, subscribers);
983
+ if (this.env === exports.Api.EEnv.DEV) {
984
+ console.groupCollapsed("MessageBroker subscription added: ", topic);
985
+ console.table(Array.from(this.subscriptions.entries()));
986
+ console.groupEnd();
987
+ }
988
+ };
989
+ /** Send message to server */
990
+ WebSocketBroker.prototype.sendMessage = function (msg) {
991
+ if (this.ws.readyState !== WebSocket.OPEN) {
992
+ return;
993
+ }
994
+ if (!this.user) {
995
+ console.error("Set user first!");
996
+ }
997
+ try {
998
+ var outgoingMessage = __assign(__assign({}, msg), { user: this.user, time: Date.now() });
999
+ this.ws.send(JSON.stringify(outgoingMessage));
1000
+ }
1001
+ catch (e) {
1002
+ console.warn(e);
1003
+ }
1004
+ };
1005
+ Object.defineProperty(WebSocketBroker.prototype, "connected", {
1006
+ get: function () {
1007
+ return this.ws.readyState === WebSocket.OPEN;
1008
+ },
1009
+ enumerable: false,
1010
+ configurable: true
1011
+ });
1012
+ /** Add a subscriber to a topic */
1013
+ WebSocketBroker.prototype.subscribe = function (topic, callback, action) {
1014
+ if (action === void 0) { action = Action.SUBSCRIBE; }
1015
+ this.addSubscriber(topic, callback);
1016
+ this.sendMessage({ topic: topic, action: action });
1017
+ if (this.env === exports.Api.EEnv.DEV) {
1018
+ console.log("Subscribe [" + action + "] called for topic", topic);
1019
+ }
1020
+ };
1021
+ /** Add a shadow subscriber to a topic */
1022
+ WebSocketBroker.prototype.subscribeShadow = function (topic, callback) {
1023
+ this.subscribe(topic, callback, Action.SUBSCRIBE_SHADOW);
1024
+ };
1025
+ /** Remove a subscriber from a topic */
1026
+ WebSocketBroker.prototype.unsubscribe = function (topic, callback) {
1027
+ var subscribers = this.subscriptions.get(topic) || [];
1028
+ this.subscriptions.set(topic, subscribers.filter(function (fn) { return fn != callback; }));
1029
+ this.sendMessage({ topic: topic, action: Action.UNSUBSCRIBE });
1030
+ if (this.env === exports.Api.EEnv.DEV) {
1031
+ console.groupCollapsed("MessageBroker subscription removed: ", topic);
1032
+ console.table(Array.from(this.subscriptions.entries()));
1033
+ console.groupEnd();
1034
+ }
1035
+ };
1036
+ WebSocketBroker.prototype.sendBroadcastMessage = function (msg) {
1037
+ this.sendMessage(__assign(__assign({}, msg), { action: Action.BROADCAST }));
1038
+ };
1039
+ WebSocketBroker.prototype.requestTopicUsers = function (topic, callback) {
1040
+ this.addSubscriber(topic, callback);
1041
+ this.sendMessage({ topic: topic, action: Action.GET_TOPIC_SUBSCRIBERS });
1042
+ };
1043
+ return WebSocketBroker;
1044
+ }());
1045
+ MessageBroker.WebSocketBroker = WebSocketBroker;
1046
+ })(exports.MessageBroker || (exports.MessageBroker = {}));
1047
+
905
1048
  (function (BruceApi) {
906
1049
  /**
907
1050
  * This is the request handler for Bruce Api,
@@ -920,19 +1063,31 @@
920
1063
  _this.loadCancelled = false;
921
1064
  _this.accountId = accountId;
922
1065
  _this.env = env !== null && env !== void 0 ? env : exports.Api.EEnv.PROD;
923
- _this.loadProm = _this.setBaseUrl(cam);
1066
+ _this.loadProm = _this.init(cam);
924
1067
  return _this;
925
1068
  }
1069
+ Object.defineProperty(Api$$1.prototype, "MessageBroker", {
1070
+ get: function () {
1071
+ return this.messageBroker;
1072
+ },
1073
+ enumerable: false,
1074
+ configurable: true
1075
+ });
926
1076
  Object.defineProperty(Api$$1.prototype, "Loading", {
927
1077
  // Indicates if the init process has finished loading.
928
- // This means the regional base url has been set.
1078
+ // This means the regional base url has been set and message broker is ready.
929
1079
  get: function () {
930
1080
  return this.loadProm;
931
1081
  },
932
1082
  enumerable: false,
933
1083
  configurable: true
934
1084
  });
935
- Api$$1.prototype.setBaseUrl = function (cam) {
1085
+ /**
1086
+ * Loads regional base url and sets up message broker.
1087
+ * @param cam
1088
+ * @returns
1089
+ */
1090
+ Api$$1.prototype.init = function (cam) {
936
1091
  var _a;
937
1092
  return __awaiter(this, void 0, void 0, function () {
938
1093
  var prefix, url, env, camApi, settings, endpoint, e_1;
@@ -981,7 +1136,9 @@
981
1136
  e_1 = _b.sent();
982
1137
  console.error(e_1);
983
1138
  return [3 /*break*/, 4];
984
- case 4: return [2 /*return*/];
1139
+ case 4:
1140
+ this.messageBroker = new exports.MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1141
+ return [2 /*return*/];
985
1142
  }
986
1143
  });
987
1144
  });
@@ -1862,7 +2019,8 @@
1862
2019
  if (typeof value == "string") {
1863
2020
  try {
1864
2021
  value = BruceVariable.SwapValues(value, entity);
1865
- return eval(value);
2022
+ var eval2 = eval; // https://rollupjs.org/guide/en/#avoiding-eval
2023
+ return eval2(value);
1866
2024
  }
1867
2025
  catch (exception) {
1868
2026
  var e = exception;
@@ -6447,7 +6605,7 @@
6447
6605
  if (pageIndex > 0) {
6448
6606
  url += (first ? "?" : "&") + "pageIndex=" + pageIndex;
6449
6607
  }
6450
- req = api.GET(url);
6608
+ req = api.GET(url, exports.Api.PrepReqParams());
6451
6609
  prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
6452
6610
  var data, e_1;
6453
6611
  return __generator(this, function (_a) {
@@ -6481,7 +6639,7 @@
6481
6639
  if (cacheData) {
6482
6640
  return [2 /*return*/, cacheData];
6483
6641
  }
6484
- req = api.GET("entityImportFile/" + fileId);
6642
+ req = api.GET("entityImportFile/" + fileId, exports.Api.PrepReqParams());
6485
6643
  api.Cache.Set(GetCacheKey(fileId), req, exports.Api.DEFAULT_CACHE_DURATION);
6486
6644
  return [2 /*return*/, req];
6487
6645
  });