bruce-models 0.7.2 → 0.7.4

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.
@@ -98,7 +98,7 @@
98
98
  ECacheKey["PendingAction"] = "pendingaction";
99
99
  ECacheKey["EntitySource"] = "entitysource";
100
100
  ECacheKey["ProgramKey"] = "programkey";
101
- ECacheKey["Ucs"] = "ucs";
101
+ ECacheKey["EntityCoords"] = "entitycoords";
102
102
  ECacheKey["Tag"] = "tag";
103
103
  ECacheKey["Attachment"] = "attachment";
104
104
  ECacheKey["Comment"] = "comment";
@@ -3962,6 +3962,184 @@
3962
3962
  BatchedDataGetter.Getter = Getter;
3963
3963
  })(exports.BatchedDataGetter || (exports.BatchedDataGetter = {}));
3964
3964
 
3965
+ (function (MathUtils) {
3966
+ /**
3967
+ * Rounds a number to a given number of decimal places.
3968
+ * @param num
3969
+ * @param decimals
3970
+ * @returns
3971
+ */
3972
+ function Round(num, decimals) {
3973
+ if (decimals === void 0) { decimals = 0; }
3974
+ if (decimals <= 0) {
3975
+ return Math.round(num);
3976
+ }
3977
+ var tmp = "1";
3978
+ for (var i = 0; i < decimals; i++) {
3979
+ tmp += "0";
3980
+ }
3981
+ var d = parseFloat(tmp);
3982
+ return Math.round((num + Number.EPSILON) * d) / d;
3983
+ }
3984
+ MathUtils.Round = Round;
3985
+ /**
3986
+ * Returns a random integer between min (inclusive) and max (inclusive).
3987
+ * @param min
3988
+ * @param max
3989
+ * @returns
3990
+ */
3991
+ function RandInt(min, max) {
3992
+ if (min == max) {
3993
+ return min;
3994
+ }
3995
+ else if (min > max) {
3996
+ throw ("Min is greater than max.");
3997
+ }
3998
+ return Math.floor(Math.random() * (max - min + 1)) + min;
3999
+ }
4000
+ MathUtils.RandInt = RandInt;
4001
+ })(exports.MathUtils || (exports.MathUtils = {}));
4002
+
4003
+ (function (EntityCoords) {
4004
+ EntityCoords.UCS_ENTITY_TYPE_ID = "Bruce_UCS_Type";
4005
+ function GetCacheKey(entityId) {
4006
+ return exports.Api.ECacheKey.EntityCoords + exports.Api.ECacheKey.Entity + exports.Api.ECacheKey.Id + entityId;
4007
+ }
4008
+ EntityCoords.GetCacheKey = GetCacheKey;
4009
+ function GetEntityCoords(api, entityId) {
4010
+ return __awaiter(this, void 0, void 0, function () {
4011
+ var cacheData, req;
4012
+ return __generator(this, function (_a) {
4013
+ cacheData = api.Cache.Get(GetCacheKey(entityId));
4014
+ if (cacheData) {
4015
+ return [2 /*return*/, cacheData];
4016
+ }
4017
+ req = api.GET("entity/" + entityId + "/ucs");
4018
+ api.Cache.Set(GetCacheKey(entityId), req, exports.Api.DEFAULT_CACHE_DURATION);
4019
+ return [2 /*return*/, req];
4020
+ });
4021
+ });
4022
+ }
4023
+ EntityCoords.GetEntityCoords = GetEntityCoords;
4024
+ function EntityRelativeToPoint(api, entityId, params) {
4025
+ return __awaiter(this, void 0, void 0, function () {
4026
+ var point, name, res;
4027
+ return __generator(this, function (_a) {
4028
+ switch (_a.label) {
4029
+ case 0:
4030
+ if (!!params.test) return [3 /*break*/, 2];
4031
+ return [4 /*yield*/, UnlinkCoords(api, entityId)];
4032
+ case 1:
4033
+ _a.sent();
4034
+ _a.label = 2;
4035
+ case 2:
4036
+ point = params.point;
4037
+ name = params.name || exports.MathUtils.Round(point.latitude, 4) + ", " + exports.MathUtils.Round(point.longitude, 4);
4038
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/ucs", {
4039
+ "ucs": {
4040
+ "Entity.ID": null,
4041
+ "name": name,
4042
+ "location": {
4043
+ "latitude": point.latitude,
4044
+ "longitude": point.longitude,
4045
+ "altitude": point.altitude,
4046
+ "coordinates": {
4047
+ "Entity.ID": entityId
4048
+ }
4049
+ }
4050
+ },
4051
+ "test": params.test
4052
+ })];
4053
+ case 3:
4054
+ res = _a.sent();
4055
+ if (!params.test) {
4056
+ api.Cache.Remove(GetCacheKey(entityId));
4057
+ }
4058
+ return [2 /*return*/, res];
4059
+ }
4060
+ });
4061
+ });
4062
+ }
4063
+ EntityCoords.EntityRelativeToPoint = EntityRelativeToPoint;
4064
+ function EntityRelativeToEpsg(api, entityId, params) {
4065
+ var _a;
4066
+ return __awaiter(this, void 0, void 0, function () {
4067
+ var epsg, name, res;
4068
+ return __generator(this, function (_b) {
4069
+ switch (_b.label) {
4070
+ case 0:
4071
+ if (!!params.test) return [3 /*break*/, 2];
4072
+ return [4 /*yield*/, UnlinkCoords(api, entityId)];
4073
+ case 1:
4074
+ _b.sent();
4075
+ _b.label = 2;
4076
+ case 2:
4077
+ epsg = params.epsg;
4078
+ name = (_a = params.name) !== null && _a !== void 0 ? _a : "EPSG: " + epsg;
4079
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/ucs", {
4080
+ "ucs": {
4081
+ "Entity.ID": null,
4082
+ "name": name,
4083
+ "location": {
4084
+ "coordinates": {
4085
+ "SRID": "EPSG:" + epsg,
4086
+ "Entity.ID": entityId
4087
+ }
4088
+ }
4089
+ },
4090
+ "test": params.test
4091
+ })];
4092
+ case 3:
4093
+ res = _b.sent();
4094
+ if (!params.test) {
4095
+ api.Cache.Remove(GetCacheKey(entityId));
4096
+ }
4097
+ return [2 /*return*/, res];
4098
+ }
4099
+ });
4100
+ });
4101
+ }
4102
+ EntityCoords.EntityRelativeToEpsg = EntityRelativeToEpsg;
4103
+ function EntityRelativeToUcs(api, entityId, params) {
4104
+ return __awaiter(this, void 0, void 0, function () {
4105
+ var ucsId, res;
4106
+ return __generator(this, function (_a) {
4107
+ switch (_a.label) {
4108
+ case 0:
4109
+ if (!!params.test) return [3 /*break*/, 2];
4110
+ return [4 /*yield*/, UnlinkCoords(api, entityId)];
4111
+ case 1:
4112
+ _a.sent();
4113
+ _a.label = 2;
4114
+ case 2:
4115
+ ucsId = params.ucsId;
4116
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/ucs", {
4117
+ "ucs": {
4118
+ "Entity.ID": ucsId
4119
+ },
4120
+ "test": params.test
4121
+ })];
4122
+ case 3:
4123
+ res = _a.sent();
4124
+ if (!params.test) {
4125
+ api.Cache.Remove(GetCacheKey(entityId));
4126
+ }
4127
+ return [2 /*return*/, res];
4128
+ }
4129
+ });
4130
+ });
4131
+ }
4132
+ EntityCoords.EntityRelativeToUcs = EntityRelativeToUcs;
4133
+ function UnlinkCoords(api, entityId) {
4134
+ return __awaiter(this, void 0, void 0, function () {
4135
+ return __generator(this, function (_a) {
4136
+ return [2 /*return*/, api.DELETE("entity/" + entityId + "/ucs")];
4137
+ });
4138
+ });
4139
+ }
4140
+ EntityCoords.UnlinkCoords = UnlinkCoords;
4141
+ })(exports.EntityCoords || (exports.EntityCoords = {}));
4142
+
3965
4143
  (function (ClientFile) {
3966
4144
  function GetCacheKey(fileId) {
3967
4145
  return "" + exports.Api.ECacheKey.ClientFile + exports.Api.ECacheKey.Id + fileId;
@@ -5183,96 +5361,6 @@
5183
5361
  })(EType = TilesetExtMapTiles.EType || (TilesetExtMapTiles.EType = {}));
5184
5362
  })(exports.TilesetExtMapTiles || (exports.TilesetExtMapTiles = {}));
5185
5363
 
5186
- (function (Ucs) {
5187
- function GetCacheKey(id, expandUsage) {
5188
- return exports.Api.ECacheKey.Ucs + exports.Api.ECacheKey.Id + id + exports.Api.ECacheKey + expandUsage;
5189
- }
5190
- Ucs.GetCacheKey = GetCacheKey;
5191
- function GetListCacheKey() {
5192
- return exports.Api.ECacheKey.Ucs;
5193
- }
5194
- Ucs.GetListCacheKey = GetListCacheKey;
5195
- var EState;
5196
- (function (EState) {
5197
- EState["Undefined"] = "undef";
5198
- EState["Prepared"] = "ready";
5199
- })(EState = Ucs.EState || (Ucs.EState = {}));
5200
- function Get(api, ucsId, expandUsage) {
5201
- return __awaiter(this, void 0, void 0, function () {
5202
- var cacheData, req;
5203
- return __generator(this, function (_a) {
5204
- if (!ucsId) {
5205
- throw ("UCS ID is required.");
5206
- }
5207
- if (!expandUsage) {
5208
- expandUsage = false;
5209
- }
5210
- cacheData = api.Cache.Get(GetCacheKey(ucsId, expandUsage));
5211
- if (cacheData) {
5212
- return [2 /*return*/, cacheData];
5213
- }
5214
- req = api.GET("ucs/" + ucsId);
5215
- api.Cache.Set(GetCacheKey(ucsId, expandUsage), req, exports.Api.DEFAULT_CACHE_DURATION);
5216
- return [2 /*return*/, req];
5217
- });
5218
- });
5219
- }
5220
- Ucs.Get = Get;
5221
- function Delete(api, ucsId) {
5222
- return __awaiter(this, void 0, void 0, function () {
5223
- return __generator(this, function (_a) {
5224
- switch (_a.label) {
5225
- case 0:
5226
- if (!ucsId) {
5227
- throw ("UCS ID is required.");
5228
- }
5229
- return [4 /*yield*/, api.DELETE("ucs/" + ucsId)];
5230
- case 1:
5231
- _a.sent();
5232
- api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Ucs + exports.Api.ECacheKey.Id + ucsId);
5233
- api.Cache.Remove(GetListCacheKey());
5234
- return [2 /*return*/];
5235
- }
5236
- });
5237
- });
5238
- }
5239
- Ucs.Delete = Delete;
5240
- function GetList(api) {
5241
- return __awaiter(this, void 0, void 0, function () {
5242
- var cacheData, req;
5243
- return __generator(this, function (_a) {
5244
- cacheData = api.Cache.Get(GetListCacheKey());
5245
- if (cacheData) {
5246
- return [2 /*return*/, cacheData];
5247
- }
5248
- req = api.GET("ucs");
5249
- api.Cache.Set(GetListCacheKey(), req, exports.Api.DEFAULT_CACHE_DURATION);
5250
- return [2 /*return*/, req];
5251
- });
5252
- });
5253
- }
5254
- Ucs.GetList = GetList;
5255
- function Update(api, data) {
5256
- return __awaiter(this, void 0, void 0, function () {
5257
- return __generator(this, function (_a) {
5258
- switch (_a.label) {
5259
- case 0:
5260
- if (!(data === null || data === void 0 ? void 0 : data.name)) {
5261
- throw ("UCS name is required.");
5262
- }
5263
- return [4 /*yield*/, api.POST("ucs" + (!data.id ? "" : "/" + data.id), data)];
5264
- case 1:
5265
- data = _a.sent();
5266
- api.Cache.RemoveByStartsWith(exports.Api.ECacheKey.Ucs + exports.Api.ECacheKey.Id + data.id);
5267
- api.Cache.Remove(GetListCacheKey());
5268
- return [2 /*return*/, data];
5269
- }
5270
- });
5271
- });
5272
- }
5273
- Ucs.Update = Update;
5274
- })(exports.Ucs || (exports.Ucs = {}));
5275
-
5276
5364
  (function (Permission) {
5277
5365
  var EPerm;
5278
5366
  (function (EPerm) {
@@ -5921,44 +6009,6 @@
5921
6009
  EncryptUtils.Cyrb53Hash = Cyrb53Hash;
5922
6010
  })(exports.EncryptUtils || (exports.EncryptUtils = {}));
5923
6011
 
5924
- (function (MathUtils) {
5925
- /**
5926
- * Rounds a number to a given number of decimal places.
5927
- * @param num
5928
- * @param decimals
5929
- * @returns
5930
- */
5931
- function Round(num, decimals) {
5932
- if (decimals === void 0) { decimals = 0; }
5933
- if (decimals <= 0) {
5934
- return Math.round(num);
5935
- }
5936
- var tmp = "1";
5937
- for (var i = 0; i < decimals; i++) {
5938
- tmp += "0";
5939
- }
5940
- var d = parseFloat(tmp);
5941
- return Math.round((num + Number.EPSILON) * d) / d;
5942
- }
5943
- MathUtils.Round = Round;
5944
- /**
5945
- * Returns a random integer between min (inclusive) and max (inclusive).
5946
- * @param min
5947
- * @param max
5948
- * @returns
5949
- */
5950
- function RandInt(min, max) {
5951
- if (min == max) {
5952
- return min;
5953
- }
5954
- else if (min > max) {
5955
- throw ("Min is greater than max.");
5956
- }
5957
- return Math.floor(Math.random() * (max - min + 1)) + min;
5958
- }
5959
- MathUtils.RandInt = RandInt;
5960
- })(exports.MathUtils || (exports.MathUtils = {}));
5961
-
5962
6012
  /**
5963
6013
  * Utility to help with url manipulation.
5964
6014
  */