bruce-models 7.1.19 → 7.1.21

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.
@@ -45,6 +45,7 @@
45
45
  ECacheKey["Entity"] = "entity";
46
46
  ECacheKey["EntityType"] = "entitytype";
47
47
  ECacheKey["EntityTypeTrigger"] = "entitytypetrigger";
48
+ ECacheKey["DataFeed"] = "datafeed";
48
49
  ECacheKey["ProjectView"] = "projectview";
49
50
  ECacheKey["ProjectViewBookmark"] = "pvbookmark";
50
51
  ECacheKey["Tileset"] = "tileset";
@@ -5188,136 +5189,166 @@
5188
5189
  if (type == "number" && field.type == EValueType.Color) {
5189
5190
  field.type = EValueType.Input;
5190
5191
  }
5191
- switch (field.type) {
5192
- case EValueType.Color:
5193
- if (type === "number") {
5194
- break;
5192
+ // Custom resolution.
5193
+ if (field.value instanceof Function) {
5194
+ value = field.value(data, tags);
5195
+ if (type == "number") {
5196
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
5197
+ value = Number(value);
5195
5198
  }
5196
- value = field.value;
5197
- value = assertColor(value);
5198
- if (value && type == "string") {
5199
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5199
+ else if (typeof value != "number") {
5200
+ value = null;
5200
5201
  }
5201
- break;
5202
- case EValueType.Gradient:
5203
- if (type === "number") {
5204
- break;
5205
- }
5206
- value = GetGradientValue(field.value, data, shouldRangesDefaultToMin);
5207
- value = assertColor(value);
5208
- if (value && type == "string") {
5209
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5202
+ }
5203
+ else if (type == "string") {
5204
+ if (typeof value == "number") {
5205
+ value = String(value);
5210
5206
  }
5211
- break;
5212
- case EValueType.RandomColor:
5213
- if (type === "number") {
5214
- break;
5207
+ else if (typeof value == "object") {
5208
+ if (isColor(value)) {
5209
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5210
+ }
5211
+ else {
5212
+ value = null;
5213
+ }
5215
5214
  }
5216
- value = exports.Color.RandomColor();
5215
+ }
5216
+ else if (type == "color") {
5217
5217
  value = assertColor(value);
5218
- if (value && type == "string") {
5219
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5220
- }
5221
- break;
5222
- case EValueType.TagColor:
5223
- if (type === "number") {
5218
+ }
5219
+ }
5220
+ else {
5221
+ switch (field.type) {
5222
+ case EValueType.Color:
5223
+ if (type === "number") {
5224
+ break;
5225
+ }
5226
+ value = field.value;
5227
+ value = assertColor(value);
5228
+ if (value && type == "string") {
5229
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5230
+ }
5224
5231
  break;
5225
- }
5226
- for (let i = 0; i < tags.length; i++) {
5227
- const tag = tags[i];
5228
- if (tag.Color) {
5229
- value = exports.Color.ColorFromStr(tag.Color);
5230
- value = assertColor(value);
5231
- if (value) {
5232
- break;
5233
- }
5232
+ case EValueType.Gradient:
5233
+ if (type === "number") {
5234
+ break;
5234
5235
  }
5235
- }
5236
- if (value && type == "string") {
5237
- const cColor = value;
5238
- value = `rgba(${cColor.red},${cColor.green},${cColor.blue},${cColor.alpha})`;
5239
- }
5240
- break;
5241
- // Input can be an arbitrary value.
5242
- // Eg: Result is a colour, a number, a string.
5243
- // This means we first calculate the value, then validate it in the context of the desired type.
5244
- case EValueType.Input:
5245
- value = GetInputValue(field.value, data);
5246
- if (value != null) {
5247
- if (type == "number") {
5248
- if (typeof value == "string" && value != "" && value != null && value != undefined) {
5249
- value = Number(value);
5250
- }
5251
- else if (typeof value != "number") {
5252
- value = null;
5253
- }
5236
+ value = GetGradientValue(field.value, data, shouldRangesDefaultToMin);
5237
+ value = assertColor(value);
5238
+ if (value && type == "string") {
5239
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5240
+ }
5241
+ break;
5242
+ case EValueType.RandomColor:
5243
+ if (type === "number") {
5244
+ break;
5245
+ }
5246
+ value = exports.Color.RandomColor();
5247
+ value = assertColor(value);
5248
+ if (value && type == "string") {
5249
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5250
+ }
5251
+ break;
5252
+ case EValueType.TagColor:
5253
+ if (type === "number") {
5254
+ break;
5254
5255
  }
5255
- else if (type == "string") {
5256
- if (typeof value == "number") {
5257
- value = String(value);
5256
+ for (let i = 0; i < tags.length; i++) {
5257
+ const tag = tags[i];
5258
+ if (tag.Color) {
5259
+ value = exports.Color.ColorFromStr(tag.Color);
5260
+ value = assertColor(value);
5261
+ if (value) {
5262
+ break;
5263
+ }
5258
5264
  }
5259
- else if (typeof value == "object") {
5260
- if (isColor(value)) {
5261
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5265
+ }
5266
+ if (value && type == "string") {
5267
+ const cColor = value;
5268
+ value = `rgba(${cColor.red},${cColor.green},${cColor.blue},${cColor.alpha})`;
5269
+ }
5270
+ break;
5271
+ // Input can be an arbitrary value.
5272
+ // Eg: Result is a colour, a number, a string.
5273
+ // This means we first calculate the value, then validate it in the context of the desired type.
5274
+ case EValueType.Input:
5275
+ value = GetInputValue(field.value, data);
5276
+ if (value != null) {
5277
+ if (type == "number") {
5278
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
5279
+ value = Number(value);
5262
5280
  }
5263
- else {
5281
+ else if (typeof value != "number") {
5264
5282
  value = null;
5265
5283
  }
5266
5284
  }
5267
- }
5268
- else if (type == "color") {
5269
- value = assertColor(value);
5270
- }
5271
- }
5272
- break;
5273
- // Mapping can be an arbitrary value.
5274
- // Eg: mapping a value to a Client File ID, or a colour, or a number.
5275
- // This means we first calculate the value, then validate it in the context of the desired type.
5276
- case EValueType.Mapping:
5277
- value = GetMappingValue(field.value, data);
5278
- if (value != null) {
5279
- if (type == "number") {
5280
- if (typeof value == "string" && value != "" && value != null && value != undefined) {
5281
- value = Number(value);
5285
+ else if (type == "string") {
5286
+ if (typeof value == "number") {
5287
+ value = String(value);
5288
+ }
5289
+ else if (typeof value == "object") {
5290
+ if (isColor(value)) {
5291
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5292
+ }
5293
+ else {
5294
+ value = null;
5295
+ }
5296
+ }
5282
5297
  }
5283
- else if (typeof value != "number") {
5284
- value = null;
5298
+ else if (type == "color") {
5299
+ value = assertColor(value);
5285
5300
  }
5286
5301
  }
5287
- else if (type == "string") {
5288
- if (typeof value == "number") {
5289
- value = String(value);
5290
- }
5291
- else if (typeof value == "object") {
5292
- if (isColor(value)) {
5293
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5302
+ break;
5303
+ // Mapping can be an arbitrary value.
5304
+ // Eg: mapping a value to a Client File ID, or a colour, or a number.
5305
+ // This means we first calculate the value, then validate it in the context of the desired type.
5306
+ case EValueType.Mapping:
5307
+ value = GetMappingValue(field.value, data);
5308
+ if (value != null) {
5309
+ if (type == "number") {
5310
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
5311
+ value = Number(value);
5294
5312
  }
5295
- else {
5313
+ else if (typeof value != "number") {
5296
5314
  value = null;
5297
5315
  }
5298
5316
  }
5317
+ else if (type == "string") {
5318
+ if (typeof value == "number") {
5319
+ value = String(value);
5320
+ }
5321
+ else if (typeof value == "object") {
5322
+ if (isColor(value)) {
5323
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
5324
+ }
5325
+ else {
5326
+ value = null;
5327
+ }
5328
+ }
5329
+ }
5330
+ else if (type == "color") {
5331
+ value = assertColor(typeof value === "number" ? String(value) : value);
5332
+ }
5299
5333
  }
5300
- else if (type == "color") {
5301
- value = assertColor(typeof value === "number" ? String(value) : value);
5302
- }
5334
+ break;
5335
+ }
5336
+ // Extra layer of validation.
5337
+ // This is a backup in case some branch above failed to convert into the right type.
5338
+ if (type == "number") {
5339
+ if (typeof value !== "number" || isNaN(value)) {
5340
+ value = null;
5303
5341
  }
5304
- break;
5305
- }
5306
- // Extra layer of validation.
5307
- // This is a backup in case some branch above failed to convert into the right type.
5308
- if (type == "number") {
5309
- if (typeof value !== "number" || isNaN(value)) {
5310
- value = null;
5311
5342
  }
5312
- }
5313
- else if (type == "color") {
5314
- if (typeof value !== "object" || !value) {
5315
- value = null;
5343
+ else if (type == "color") {
5344
+ if (typeof value !== "object" || !value) {
5345
+ value = null;
5346
+ }
5316
5347
  }
5317
- }
5318
- else if (type == "string") {
5319
- if (typeof value !== "string" || !value) {
5320
- value = null;
5348
+ else if (type == "string") {
5349
+ if (typeof value !== "string" || !value) {
5350
+ value = null;
5351
+ }
5321
5352
  }
5322
5353
  }
5323
5354
  if (value != null) {
@@ -15428,6 +15459,203 @@
15428
15459
  DataLabGroup.Delete = Delete;
15429
15460
  })(exports.DataLabGroup || (exports.DataLabGroup = {}));
15430
15461
 
15462
+ (function (DataFeed) {
15463
+ /**
15464
+ * Known data feed types.
15465
+ */
15466
+ let EType;
15467
+ (function (EType) {
15468
+ EType["WFS"] = "WFS";
15469
+ })(EType = DataFeed.EType || (DataFeed.EType = {}));
15470
+ /**
15471
+ * Returns details of a data feed by ID or Key.
15472
+ * @param params
15473
+ */
15474
+ function Get(params) {
15475
+ return __awaiter(this, void 0, void 0, function* () {
15476
+ let { api, dataFeedId, req: reqParams } = params;
15477
+ if (dataFeedId == null || dataFeedId === "") {
15478
+ throw ("Data Feed ID or Key is required.");
15479
+ }
15480
+ if (!api) {
15481
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
15482
+ }
15483
+ const key = GetCacheKey(dataFeedId);
15484
+ const cache = api.GetCacheItem(key, reqParams);
15485
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
15486
+ return cache.data;
15487
+ }
15488
+ const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
15489
+ try {
15490
+ const data = yield api.GET(`dataFeed/${dataFeedId}`, exports.Api.PrepReqParams(reqParams));
15491
+ res({
15492
+ dataFeed: ParseResponse(data)
15493
+ });
15494
+ }
15495
+ catch (e) {
15496
+ rej(e);
15497
+ }
15498
+ }));
15499
+ api.SetCacheItem({
15500
+ key,
15501
+ value: req,
15502
+ req: reqParams
15503
+ });
15504
+ return req;
15505
+ });
15506
+ }
15507
+ DataFeed.Get = Get;
15508
+ /**
15509
+ * Returns a list of all data feed records.
15510
+ * @param params
15511
+ */
15512
+ function GetList(params) {
15513
+ return __awaiter(this, void 0, void 0, function* () {
15514
+ if (!params) {
15515
+ params = {};
15516
+ }
15517
+ let { api, req: reqParams } = params;
15518
+ if (!api) {
15519
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
15520
+ }
15521
+ const key = GetListCacheKey();
15522
+ const cache = api.GetCacheItem(key, reqParams);
15523
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
15524
+ return cache.data;
15525
+ }
15526
+ const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
15527
+ try {
15528
+ const data = yield api.GET("dataFeeds", exports.Api.PrepReqParams(reqParams));
15529
+ res({
15530
+ dataFeeds: ParseListResponse(data)
15531
+ });
15532
+ }
15533
+ catch (e) {
15534
+ rej(e);
15535
+ }
15536
+ }));
15537
+ api.SetCacheItem({
15538
+ key,
15539
+ value: req,
15540
+ req: reqParams
15541
+ });
15542
+ return req;
15543
+ });
15544
+ }
15545
+ DataFeed.GetList = GetList;
15546
+ /**
15547
+ * Creates or updates a data feed record.
15548
+ * This calls: POST dataFeed/{data_feed_id} where 0 creates new.
15549
+ * @param params
15550
+ */
15551
+ function Update(params) {
15552
+ return __awaiter(this, void 0, void 0, function* () {
15553
+ let { api, dataFeed: data, req: reqParams } = params;
15554
+ if (!api) {
15555
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
15556
+ }
15557
+ if (!data) {
15558
+ data = {};
15559
+ }
15560
+ const id = data.ID && data.ID > 0 ? data.ID : 0;
15561
+ const res = yield api.POST(`dataFeed/${id}`, data, exports.Api.PrepReqParams(reqParams));
15562
+ // Invalidate list and likely keys.
15563
+ api.Cache.Remove(GetListCacheKey());
15564
+ if (id > 0) {
15565
+ api.Cache.Remove(GetCacheKey(id));
15566
+ }
15567
+ if (data.Key) {
15568
+ api.Cache.Remove(GetCacheKey(data.Key));
15569
+ }
15570
+ const parsed = ParseResponse(res);
15571
+ if (parsed === null || parsed === void 0 ? void 0 : parsed.ID) {
15572
+ api.Cache.Remove(GetCacheKey(parsed.ID));
15573
+ }
15574
+ if (parsed === null || parsed === void 0 ? void 0 : parsed.Key) {
15575
+ api.Cache.Remove(GetCacheKey(parsed.Key));
15576
+ }
15577
+ return {
15578
+ dataFeed: parsed
15579
+ };
15580
+ });
15581
+ }
15582
+ DataFeed.Update = Update;
15583
+ /**
15584
+ * Deletes a data feed by numeric ID.
15585
+ * @param params
15586
+ */
15587
+ function Delete(params) {
15588
+ return __awaiter(this, void 0, void 0, function* () {
15589
+ let { api, dataFeedId, req: reqParams } = params;
15590
+ if (!dataFeedId || dataFeedId <= 0) {
15591
+ throw ("Data Feed ID is required.");
15592
+ }
15593
+ if (!api) {
15594
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
15595
+ }
15596
+ yield api.DELETE(`dataFeed/${dataFeedId}`, exports.Api.PrepReqParams(reqParams));
15597
+ api.Cache.Remove(GetCacheKey(dataFeedId));
15598
+ api.Cache.Remove(GetListCacheKey());
15599
+ });
15600
+ }
15601
+ DataFeed.Delete = Delete;
15602
+ /**
15603
+ * Normalizes response from data feed get/update endpoints.
15604
+ */
15605
+ function ParseResponse(response) {
15606
+ var _a, _b, _c, _d, _e, _f;
15607
+ const parsed = parseObject$2(response);
15608
+ const parsedResult = (_a = parseObject$2(parsed === null || parsed === void 0 ? void 0 : parsed.Result)) !== null && _a !== void 0 ? _a : parsed === null || parsed === void 0 ? void 0 : parsed.Result;
15609
+ return (_f = (_e = (_d = (_c = (_b = parsed === null || parsed === void 0 ? void 0 : parsed.DataFeed) !== null && _b !== void 0 ? _b : parsed === null || parsed === void 0 ? void 0 : parsed.BruceDataFeed) !== null && _c !== void 0 ? _c : parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.DataFeed) !== null && _d !== void 0 ? _d : parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.BruceDataFeed) !== null && _e !== void 0 ? _e : parsedResult) !== null && _f !== void 0 ? _f : parsed;
15610
+ }
15611
+ DataFeed.ParseResponse = ParseResponse;
15612
+ /**
15613
+ * Normalizes response from data feed list endpoint.
15614
+ */
15615
+ function ParseListResponse(response) {
15616
+ var _a, _b, _c, _d, _e, _f, _g, _h;
15617
+ const parsed = parseObject$2(response);
15618
+ const parsedResult = (_a = parseObject$2(parsed === null || parsed === void 0 ? void 0 : parsed.Result)) !== null && _a !== void 0 ? _a : parsed === null || parsed === void 0 ? void 0 : parsed.Result;
15619
+ const list = (_h = (_g = (_f = (_e = (_d = (_c = (_b = parsed === null || parsed === void 0 ? void 0 : parsed.Items) !== null && _b !== void 0 ? _b : parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.Items) !== null && _c !== void 0 ? _c : parsed === null || parsed === void 0 ? void 0 : parsed.DataFeeds) !== null && _d !== void 0 ? _d : parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.DataFeeds) !== null && _e !== void 0 ? _e : parsed === null || parsed === void 0 ? void 0 : parsed.BruceDataFeeds) !== null && _f !== void 0 ? _f : parsedResult === null || parsedResult === void 0 ? void 0 : parsedResult.BruceDataFeeds) !== null && _g !== void 0 ? _g : parsedResult) !== null && _h !== void 0 ? _h : parsed;
15620
+ if (Array.isArray(list)) {
15621
+ return list;
15622
+ }
15623
+ return [];
15624
+ }
15625
+ DataFeed.ParseListResponse = ParseListResponse;
15626
+ /**
15627
+ * Returns cache identifier for a data feed by ID/Key.
15628
+ * @param idOrKey
15629
+ * @returns
15630
+ */
15631
+ function GetCacheKey(idOrKey) {
15632
+ return `${exports.Api.ECacheKey.DataFeed}${exports.Api.ECacheKey.Id}${idOrKey}`;
15633
+ }
15634
+ DataFeed.GetCacheKey = GetCacheKey;
15635
+ /**
15636
+ * Returns cache identifier for the list of data feeds.
15637
+ * @returns
15638
+ */
15639
+ function GetListCacheKey() {
15640
+ return exports.Api.ECacheKey.DataFeed;
15641
+ }
15642
+ DataFeed.GetListCacheKey = GetListCacheKey;
15643
+ })(exports.DataFeed || (exports.DataFeed = {}));
15644
+ function parseObject$2(data) {
15645
+ if (data == null || data == undefined) {
15646
+ return null;
15647
+ }
15648
+ if (typeof data == "string") {
15649
+ try {
15650
+ return JSON.parse(data);
15651
+ }
15652
+ catch (_a) {
15653
+ return null;
15654
+ }
15655
+ }
15656
+ return data;
15657
+ }
15658
+
15431
15659
  (function (ImportAssembly) {
15432
15660
  function Analyze(params) {
15433
15661
  return __awaiter(this, void 0, void 0, function* () {
@@ -17140,7 +17368,7 @@
17140
17368
  })(exports.ChangeSet || (exports.ChangeSet = {}));
17141
17369
 
17142
17370
  // This is updated with the package.json version on build.
17143
- const VERSION = "7.1.19";
17371
+ const VERSION = "7.1.21";
17144
17372
 
17145
17373
  exports.VERSION = VERSION;
17146
17374
  exports.AbstractApi = AbstractApi;