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
@@ -917,6 +917,150 @@ var CamApi;
917
917
  CamApi.Api = Api$$1;
918
918
  })(CamApi || (CamApi = {}));
919
919
 
920
+ var MessageBroker;
921
+ (function (MessageBroker) {
922
+ var Action;
923
+ (function (Action) {
924
+ Action["SUBSCRIBE"] = "subscribe";
925
+ Action["SUBSCRIBE_SHADOW"] = "subscribeShadow";
926
+ Action["UNSUBSCRIBE"] = "unsubscribe";
927
+ Action["BROADCAST"] = "broadcast";
928
+ Action["GET_TOPIC_SUBSCRIBERS"] = "getTopicSubscribers"; // requests topic subscribers without subscribing
929
+ })(Action = MessageBroker.Action || (MessageBroker.Action = {}));
930
+ /** Events types any component may get from server */
931
+ var Event;
932
+ (function (Event) {
933
+ Event["SAVED"] = "saved";
934
+ Event["UPDATED"] = "updated";
935
+ Event["DELETED"] = "deleted";
936
+ Event["EDIT_STARTED"] = "editStarted";
937
+ Event["EDIT_FINISHED"] = "editFinished";
938
+ Event["USERS_UPDATE"] = "usersUpdate";
939
+ })(Event = MessageBroker.Event || (MessageBroker.Event = {}));
940
+ /** Communicates with a server message broker */
941
+ var WebSocketBroker = /** @class */ (function () {
942
+ function WebSocketBroker(uri, env) {
943
+ this.uri = uri;
944
+ this.env = env;
945
+ this.subscriptions = new Map();
946
+ this.reconnects = 0;
947
+ this.maxReconnects = 5;
948
+ this.connect();
949
+ }
950
+ WebSocketBroker.prototype.connect = function () {
951
+ try {
952
+ this.ws = new WebSocket(this.formatApiUri(this.uri));
953
+ this.ws.onopen = this.onOpen.bind(this);
954
+ this.ws.onmessage = this.onMessage.bind(this);
955
+ this.ws.onerror = this.onError.bind(this);
956
+ this.ws.onclose = this.onClose.bind(this);
957
+ }
958
+ catch (e) {
959
+ console.error(e);
960
+ }
961
+ };
962
+ WebSocketBroker.prototype.formatApiUri = function (uri) {
963
+ var ws = document.location.protocol === "https:" ? "wss" : "ws";
964
+ return uri.replace(/^(https|http)/, ws) + "websocket";
965
+ };
966
+ WebSocketBroker.prototype.setUser = function (user) {
967
+ this.user = this.user ? this.user : user;
968
+ };
969
+ WebSocketBroker.prototype.onOpen = function (ev) {
970
+ if (this.env === Api.EEnv.DEV) {
971
+ console.log("MessageBroker connection opened: ", ev);
972
+ }
973
+ };
974
+ WebSocketBroker.prototype.onClose = function (ev) {
975
+ var _this = this;
976
+ if (this.env === Api.EEnv.DEV) {
977
+ console.log("MessageBroker connection closed, trying to reconnect: ", ev);
978
+ }
979
+ if (this.reconnects < this.maxReconnects) {
980
+ this.reconnects += 1;
981
+ setTimeout(function () { return _this.connect(); }, 5000 * this.reconnects);
982
+ }
983
+ };
984
+ WebSocketBroker.prototype.onMessage = function (ev) {
985
+ var _a;
986
+ var data = JSON.parse(ev.data);
987
+ (_a = this.subscriptions.get(data.topic)) === null || _a === void 0 ? void 0 : _a.forEach(function (cb) { return cb(data); });
988
+ };
989
+ WebSocketBroker.prototype.onError = function (ev) {
990
+ console.error("MessageBroker connection error: ", ev);
991
+ };
992
+ WebSocketBroker.prototype.addSubscriber = function (topic, callback) {
993
+ var subscribers = this.subscriptions.get(topic) || [];
994
+ if (subscribers.includes(callback)) {
995
+ return;
996
+ }
997
+ subscribers.push(callback);
998
+ this.subscriptions.set(topic, subscribers);
999
+ if (this.env === Api.EEnv.DEV) {
1000
+ console.groupCollapsed("MessageBroker subscription added: ", topic);
1001
+ console.table(Array.from(this.subscriptions.entries()));
1002
+ console.groupEnd();
1003
+ }
1004
+ };
1005
+ /** Send message to server */
1006
+ WebSocketBroker.prototype.sendMessage = function (msg) {
1007
+ if (this.ws.readyState !== WebSocket.OPEN) {
1008
+ return;
1009
+ }
1010
+ if (!this.user) {
1011
+ console.error("Set user first!");
1012
+ }
1013
+ try {
1014
+ var outgoingMessage = __assign(__assign({}, msg), { user: this.user, time: Date.now() });
1015
+ this.ws.send(JSON.stringify(outgoingMessage));
1016
+ }
1017
+ catch (e) {
1018
+ console.warn(e);
1019
+ }
1020
+ };
1021
+ Object.defineProperty(WebSocketBroker.prototype, "connected", {
1022
+ get: function () {
1023
+ return this.ws.readyState === WebSocket.OPEN;
1024
+ },
1025
+ enumerable: false,
1026
+ configurable: true
1027
+ });
1028
+ /** Add a subscriber to a topic */
1029
+ WebSocketBroker.prototype.subscribe = function (topic, callback, action) {
1030
+ if (action === void 0) { action = Action.SUBSCRIBE; }
1031
+ this.addSubscriber(topic, callback);
1032
+ this.sendMessage({ topic: topic, action: action });
1033
+ if (this.env === Api.EEnv.DEV) {
1034
+ console.log("Subscribe [" + action + "] called for topic", topic);
1035
+ }
1036
+ };
1037
+ /** Add a shadow subscriber to a topic */
1038
+ WebSocketBroker.prototype.subscribeShadow = function (topic, callback) {
1039
+ this.subscribe(topic, callback, Action.SUBSCRIBE_SHADOW);
1040
+ };
1041
+ /** Remove a subscriber from a topic */
1042
+ WebSocketBroker.prototype.unsubscribe = function (topic, callback) {
1043
+ var subscribers = this.subscriptions.get(topic) || [];
1044
+ this.subscriptions.set(topic, subscribers.filter(function (fn) { return fn != callback; }));
1045
+ this.sendMessage({ topic: topic, action: Action.UNSUBSCRIBE });
1046
+ if (this.env === Api.EEnv.DEV) {
1047
+ console.groupCollapsed("MessageBroker subscription removed: ", topic);
1048
+ console.table(Array.from(this.subscriptions.entries()));
1049
+ console.groupEnd();
1050
+ }
1051
+ };
1052
+ WebSocketBroker.prototype.sendBroadcastMessage = function (msg) {
1053
+ this.sendMessage(__assign(__assign({}, msg), { action: Action.BROADCAST }));
1054
+ };
1055
+ WebSocketBroker.prototype.requestTopicUsers = function (topic, callback) {
1056
+ this.addSubscriber(topic, callback);
1057
+ this.sendMessage({ topic: topic, action: Action.GET_TOPIC_SUBSCRIBERS });
1058
+ };
1059
+ return WebSocketBroker;
1060
+ }());
1061
+ MessageBroker.WebSocketBroker = WebSocketBroker;
1062
+ })(MessageBroker || (MessageBroker = {}));
1063
+
920
1064
  var BruceApi;
921
1065
  (function (BruceApi) {
922
1066
  /**
@@ -936,19 +1080,31 @@ var BruceApi;
936
1080
  _this.loadCancelled = false;
937
1081
  _this.accountId = accountId;
938
1082
  _this.env = env !== null && env !== void 0 ? env : Api.EEnv.PROD;
939
- _this.loadProm = _this.setBaseUrl(cam);
1083
+ _this.loadProm = _this.init(cam);
940
1084
  return _this;
941
1085
  }
1086
+ Object.defineProperty(Api$$1.prototype, "MessageBroker", {
1087
+ get: function () {
1088
+ return this.messageBroker;
1089
+ },
1090
+ enumerable: false,
1091
+ configurable: true
1092
+ });
942
1093
  Object.defineProperty(Api$$1.prototype, "Loading", {
943
1094
  // Indicates if the init process has finished loading.
944
- // This means the regional base url has been set.
1095
+ // This means the regional base url has been set and message broker is ready.
945
1096
  get: function () {
946
1097
  return this.loadProm;
947
1098
  },
948
1099
  enumerable: false,
949
1100
  configurable: true
950
1101
  });
951
- Api$$1.prototype.setBaseUrl = function (cam) {
1102
+ /**
1103
+ * Loads regional base url and sets up message broker.
1104
+ * @param cam
1105
+ * @returns
1106
+ */
1107
+ Api$$1.prototype.init = function (cam) {
952
1108
  var _a;
953
1109
  return __awaiter(this, void 0, void 0, function () {
954
1110
  var prefix, url, env, camApi, settings, endpoint, e_1;
@@ -997,7 +1153,9 @@ var BruceApi;
997
1153
  e_1 = _b.sent();
998
1154
  console.error(e_1);
999
1155
  return [3 /*break*/, 4];
1000
- case 4: return [2 /*return*/];
1156
+ case 4:
1157
+ this.messageBroker = new MessageBroker.WebSocketBroker(this.baseUrl, this.env);
1158
+ return [2 /*return*/];
1001
1159
  }
1002
1160
  });
1003
1161
  });
@@ -1894,7 +2052,8 @@ var Calculator;
1894
2052
  if (typeof value == "string") {
1895
2053
  try {
1896
2054
  value = BruceVariable.SwapValues(value, entity);
1897
- return eval(value);
2055
+ var eval2 = eval; // https://rollupjs.org/guide/en/#avoiding-eval
2056
+ return eval2(value);
1898
2057
  }
1899
2058
  catch (exception) {
1900
2059
  var e = exception;
@@ -6656,7 +6815,7 @@ var ImportedFile;
6656
6815
  if (pageIndex > 0) {
6657
6816
  url += (first ? "?" : "&") + "pageIndex=" + pageIndex;
6658
6817
  }
6659
- req = api.GET(url);
6818
+ req = api.GET(url, Api.PrepReqParams());
6660
6819
  prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
6661
6820
  var data, e_1;
6662
6821
  return __generator(this, function (_a) {
@@ -6690,7 +6849,7 @@ var ImportedFile;
6690
6849
  if (cacheData) {
6691
6850
  return [2 /*return*/, cacheData];
6692
6851
  }
6693
- req = api.GET("entityImportFile/" + fileId);
6852
+ req = api.GET("entityImportFile/" + fileId, Api.PrepReqParams());
6694
6853
  api.Cache.Set(GetCacheKey(fileId), req, Api.DEFAULT_CACHE_DURATION);
6695
6854
  return [2 /*return*/, req];
6696
6855
  });
@@ -6699,5 +6858,5 @@ var ImportedFile;
6699
6858
  ImportedFile.Get = Get;
6700
6859
  })(ImportedFile || (ImportedFile = {}));
6701
6860
 
6702
- export { AnnDocument, CustomForm, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, PendingAction, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile };
6861
+ export { AnnDocument, CustomForm, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, PendingAction, MessageBroker, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile };
6703
6862
  //# sourceMappingURL=bruce-models.es5.js.map