bruce-models 7.1.53 → 7.1.55

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.
@@ -2734,6 +2734,89 @@ var Account;
2734
2734
  Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
2735
2735
  })(Account || (Account = {}));
2736
2736
 
2737
+ var AccountAudit;
2738
+ (function (AccountAudit) {
2739
+ let EType;
2740
+ (function (EType) {
2741
+ EType["LOG"] = "L";
2742
+ EType["CREATE"] = "C";
2743
+ EType["UPDATE"] = "U";
2744
+ EType["DELETE"] = "D";
2745
+ })(EType = AccountAudit.EType || (AccountAudit.EType = {}));
2746
+ let ESeverity;
2747
+ (function (ESeverity) {
2748
+ ESeverity["DEBUG"] = "D";
2749
+ ESeverity["INFO"] = "I";
2750
+ ESeverity["WARN"] = "W";
2751
+ ESeverity["ERROR"] = "E";
2752
+ })(ESeverity = AccountAudit.ESeverity || (AccountAudit.ESeverity = {}));
2753
+ let EDetailLevel;
2754
+ (function (EDetailLevel) {
2755
+ EDetailLevel["SUMMARY"] = "summary";
2756
+ EDetailLevel["FULL"] = "full";
2757
+ })(EDetailLevel = AccountAudit.EDetailLevel || (AccountAudit.EDetailLevel = {}));
2758
+ let EAction;
2759
+ (function (EAction) {
2760
+ EAction["CREATED"] = "Created";
2761
+ EAction["UPDATED"] = "Updated";
2762
+ EAction["DELETED"] = "Deleted";
2763
+ })(EAction = AccountAudit.EAction || (AccountAudit.EAction = {}));
2764
+ let EOrderBy;
2765
+ (function (EOrderBy) {
2766
+ EOrderBy["ID"] = "ID";
2767
+ EOrderBy["LOGGED"] = "Logged";
2768
+ EOrderBy["CREATED"] = "Created";
2769
+ EOrderBy["CREATED_DATE"] = "CreatedDate";
2770
+ EOrderBy["SEVERITY"] = "Severity";
2771
+ EOrderBy["TYPE"] = "Type";
2772
+ EOrderBy["ACTION"] = "Action";
2773
+ EOrderBy["MESSAGE"] = "Message";
2774
+ EOrderBy["CONCEPT"] = "Concept";
2775
+ EOrderBy["SCOPE"] = "Scope";
2776
+ EOrderBy["USER_ID"] = "User.ID";
2777
+ })(EOrderBy = AccountAudit.EOrderBy || (AccountAudit.EOrderBy = {}));
2778
+ function GetConceptList(params) {
2779
+ return __awaiter(this, void 0, void 0, function* () {
2780
+ let { api, req: reqParams, concept, pageSize, pageIndex, lastSeenId, search, orderBy, sortOrder, recordId, detailLevel } = params;
2781
+ if (!api) {
2782
+ api = ENVIRONMENT.Api().GetBruceApi();
2783
+ }
2784
+ if (!concept) {
2785
+ throw new Error("Concept is required.");
2786
+ }
2787
+ const urlParams = new URLSearchParams();
2788
+ if (pageSize != null) {
2789
+ urlParams.append("PageSize", String(pageSize));
2790
+ }
2791
+ if (pageIndex != null) {
2792
+ urlParams.append("PageIndex", String(pageIndex));
2793
+ }
2794
+ if (lastSeenId != null) {
2795
+ urlParams.append("LastSeenID", String(lastSeenId));
2796
+ }
2797
+ if (search) {
2798
+ urlParams.append("Search", search);
2799
+ }
2800
+ if (orderBy) {
2801
+ urlParams.append("OrderBy", orderBy);
2802
+ }
2803
+ if (sortOrder) {
2804
+ urlParams.append("SortOrder", sortOrder);
2805
+ }
2806
+ if (recordId) {
2807
+ urlParams.append("RecordID", recordId);
2808
+ }
2809
+ if (detailLevel) {
2810
+ urlParams.append("DetailLevel", detailLevel);
2811
+ }
2812
+ const query = urlParams.toString();
2813
+ const route = `v3/accountAudits/concept/${Api.Encode(String(concept))}`;
2814
+ return api.GET(query ? `${route}?${query}` : route, Api.PrepReqParams(reqParams));
2815
+ });
2816
+ }
2817
+ AccountAudit.GetConceptList = GetConceptList;
2818
+ })(AccountAudit || (AccountAudit = {}));
2819
+
2737
2820
  /**
2738
2821
  * Account Features are a set of flags that can be enabled or disabled for an account.
2739
2822
  * These flags usually represent how data is stored and managed.
@@ -7200,12 +7283,234 @@ var Calculator;
7200
7283
  EValueType[EValueType["RandomColor"] = 5] = "RandomColor";
7201
7284
  })(EValueType = Calculator.EValueType || (Calculator.EValueType = {}));
7202
7285
  /**
7203
- * Calculates a value-type 'T' based on given set of fields.
7204
- * The supplied data + tags are fed into the calculation.
7205
- * When a value fails to be calculated, the 'defaultValue' is returned.
7206
- * If no 'defaultValue' is provided, then 'null' is returned.
7286
+ * Decodes an effective string produced by TraceCalculate back into a structured object.
7287
+ * Returns null if the string is null, empty, or does not match the expected format.
7207
7288
  */
7208
- function Calculate(params) {
7289
+ function DecodeEffective(effective) {
7290
+ if (!effective) {
7291
+ return null;
7292
+ }
7293
+ // Format: f{index}:{type}[:{part1}[:{part2}]]
7294
+ const match = effective.match(/^f(\d+):([^:]+)(?::([^:]+)(?::([^:]+))?)?$/);
7295
+ if (!match) {
7296
+ return null;
7297
+ }
7298
+ const fieldIndex = parseInt(match[1], 10);
7299
+ const type = match[2];
7300
+ const part1 = match[3] != null ? decodeEffective(match[3]) : null;
7301
+ const part2 = match[4] != null ? decodeEffective(match[4]) : null;
7302
+ const base = { type, fieldIndex };
7303
+ switch (type) {
7304
+ case "color":
7305
+ if (part1 == null) {
7306
+ return null;
7307
+ }
7308
+ return Object.assign(Object.assign({}, base), { colorStr: part1 });
7309
+ case "gradient":
7310
+ case "mapping":
7311
+ return Object.assign(Object.assign(Object.assign({}, base), (part1 != null && { path: part1 })), (part2 != null && { entityValue: part2 }));
7312
+ case "input":
7313
+ if (part1 == null || part2 == null) {
7314
+ return null;
7315
+ }
7316
+ return Object.assign(Object.assign({}, base), { template: part1, resolvedValue: part2 });
7317
+ case "tag":
7318
+ if (part1 == null) {
7319
+ return null;
7320
+ }
7321
+ return Object.assign(Object.assign({}, base), { tagColor: part1 });
7322
+ case "random":
7323
+ case "fn":
7324
+ return base;
7325
+ default:
7326
+ return null;
7327
+ }
7328
+ }
7329
+ Calculator.DecodeEffective = DecodeEffective;
7330
+ function encodeEffective(str) {
7331
+ const s = String(str == null ? "" : str);
7332
+ try {
7333
+ if (typeof Buffer !== "undefined") {
7334
+ return Buffer.from(s).toString("base64").replace(/=+$/, "");
7335
+ }
7336
+ // Browser fallback
7337
+ return btoa(s).replace(/=+$/, "");
7338
+ }
7339
+ catch (e) {
7340
+ return encodeURIComponent(s);
7341
+ }
7342
+ }
7343
+ function decodeEffective(encoded) {
7344
+ try {
7345
+ if (typeof Buffer !== "undefined") {
7346
+ return Buffer.from(encoded, "base64").toString("utf8");
7347
+ }
7348
+ return atob(encoded);
7349
+ }
7350
+ catch (e) {
7351
+ return decodeURIComponent(encoded);
7352
+ }
7353
+ }
7354
+ function _getMappingTrace(value, entity) {
7355
+ const attrPaths = parseLegacyPath(value.field);
7356
+ for (let i = 0; i < attrPaths.length; i++) {
7357
+ const attrPath = attrPaths[i];
7358
+ let eValue = Entity.GetValue({
7359
+ entity: entity,
7360
+ path: attrPath
7361
+ });
7362
+ let isValueNum = !isNaN(+eValue);
7363
+ if (eValue == null) {
7364
+ isValueNum = false;
7365
+ }
7366
+ for (let j = 0; j < value.values.length; j++) {
7367
+ const option = value.values[j];
7368
+ const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
7369
+ for (let k = 0; k < fieldValues.length; k++) {
7370
+ let mapValue = fieldValues[k];
7371
+ // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
7372
+ // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
7373
+ if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
7374
+ try {
7375
+ let jsEval = mapValue.replace("JS:", "").trim();
7376
+ const attrPathStr = PathUtils.Wrap(attrPath);
7377
+ jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
7378
+ jsEval = BruceVariable.SwapValues({
7379
+ str: jsEval,
7380
+ entity: entity
7381
+ });
7382
+ // https://rollupjs.org/guide/en/#avoiding-eval
7383
+ // This stops eval warning.
7384
+ const eval2 = eval;
7385
+ mapValue = eval2(jsEval);
7386
+ if (mapValue) {
7387
+ return { result: option.appliedValue, attrPath, eValue };
7388
+ }
7389
+ else {
7390
+ continue;
7391
+ }
7392
+ }
7393
+ catch (exception) {
7394
+ const e = exception;
7395
+ let suppress = false;
7396
+ if (e && typeof e == "object") {
7397
+ const msg = e.message;
7398
+ suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
7399
+ }
7400
+ if (!suppress) {
7401
+ console.error(e);
7402
+ }
7403
+ // Eval failed, therefor not a valid mapping-row.
7404
+ continue;
7405
+ }
7406
+ }
7407
+ let isMapValueNum = !isNaN(+mapValue);
7408
+ if (isMapValueNum == null) {
7409
+ isMapValueNum = false;
7410
+ }
7411
+ if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
7412
+ if (+mapValue == +eValue) {
7413
+ return { result: option.appliedValue, attrPath, eValue };
7414
+ }
7415
+ const mapSplit = mapValue.split("-");
7416
+ if (mapSplit.length == 2) {
7417
+ const min = mapSplit[0];
7418
+ const max = mapSplit[1];
7419
+ if (min != "") {
7420
+ if (+eValue < +min) {
7421
+ continue;
7422
+ }
7423
+ }
7424
+ if (max != "") {
7425
+ if (+eValue > +max) {
7426
+ continue;
7427
+ }
7428
+ }
7429
+ if (min == "" && max == "") {
7430
+ continue;
7431
+ }
7432
+ return { result: option.appliedValue, attrPath, eValue };
7433
+ }
7434
+ }
7435
+ else {
7436
+ if (mapValue == eValue) {
7437
+ return { result: option.appliedValue, attrPath, eValue };
7438
+ }
7439
+ // Case where Entity value is a boolean but the mapping value is a string.
7440
+ // Common as mapping value is typically a user-entered string.
7441
+ else if (typeof eValue === "boolean" && typeof mapValue === "string") {
7442
+ const eValueStr = eValue ? "true" : "false";
7443
+ if (mapValue.toLowerCase() == eValueStr) {
7444
+ return { result: option.appliedValue, attrPath, eValue };
7445
+ }
7446
+ }
7447
+ // Handling possible case where the opposite is true.
7448
+ // Have not seen this happen yet, but preparing for any future cases.
7449
+ else if (typeof mapValue === "boolean" && typeof eValue === "string") {
7450
+ const mapValueStr = mapValue ? "true" : "false";
7451
+ if (mapValueStr == eValue.toLowerCase()) {
7452
+ return { result: option.appliedValue, attrPath, eValue };
7453
+ }
7454
+ }
7455
+ }
7456
+ }
7457
+ }
7458
+ }
7459
+ return { result: null, attrPath: null, eValue: null };
7460
+ }
7461
+ function _getGradientTrace(value, entity, defaultToMin) {
7462
+ const min = +value.points[0].position;
7463
+ const max = +value.points[value.points.length - 1].position;
7464
+ const attrPaths = parseLegacyPath(value.field);
7465
+ for (let i = 0; i < attrPaths.length; i++) {
7466
+ const attrPath = attrPaths[i];
7467
+ let eValue = Entity.GetValue({
7468
+ entity: entity,
7469
+ path: attrPath
7470
+ });
7471
+ if (typeof eValue == "string") {
7472
+ eValue = Number(eValue);
7473
+ }
7474
+ if ((!eValue && eValue != 0) || isNaN(eValue)) {
7475
+ continue;
7476
+ }
7477
+ if (eValue >= max) {
7478
+ return { result: Color.ColorFromStr(value.points[value.points.length - 1].color), attrPath, eValue };
7479
+ }
7480
+ else if (eValue <= min) {
7481
+ return { result: Color.ColorFromStr(value.points[0].color), attrPath, eValue };
7482
+ }
7483
+ for (let j = 0; j < value.points.length - 1; j++) {
7484
+ const pointA = value.points[j];
7485
+ const pointB = value.points[j + 1];
7486
+ if (eValue >= pointA.position && eValue <= pointB.position) {
7487
+ if (pointA.position == pointB.position) {
7488
+ return { result: Color.ColorFromStr(pointA.color), attrPath, eValue };
7489
+ }
7490
+ const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
7491
+ const colorA = Color.ColorFromStr(pointA.color);
7492
+ const colorB = Color.ColorFromStr(pointB.color);
7493
+ return {
7494
+ result: {
7495
+ red: colorA.red + (colorB.red - colorA.red) * distance,
7496
+ green: colorA.green + (colorB.green - colorA.green) * distance,
7497
+ blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
7498
+ alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
7499
+ },
7500
+ attrPath,
7501
+ eValue
7502
+ };
7503
+ }
7504
+ }
7505
+ }
7506
+ // Fallback to min (static, no data path resolved).
7507
+ return { result: Color.ColorFromStr(value.points[0].color), attrPath: null, eValue: null };
7508
+ }
7509
+ /**
7510
+ * Like Calculate, but also returns an 'effective' key describing how the value
7511
+ * was derived. See ITraceResult for the key format.
7512
+ */
7513
+ function TraceCalculate(params) {
7209
7514
  let { fields, tags, data, defaultValue, type } = params;
7210
7515
  // If params doesn't include a defaultValue, use null.
7211
7516
  // Though passing in undefined is valid!
@@ -7213,7 +7518,7 @@ var Calculator;
7213
7518
  defaultValue = null;
7214
7519
  }
7215
7520
  if (fields == null) {
7216
- return defaultValue;
7521
+ return { value: defaultValue, effective: null };
7217
7522
  }
7218
7523
  if (data == null || typeof data != "object") {
7219
7524
  data = {};
@@ -7258,16 +7563,21 @@ var Calculator;
7258
7563
  }
7259
7564
  return false;
7260
7565
  };
7261
- // Calculate the value.
7262
7566
  let value = null;
7567
+ let computedEffective = null;
7263
7568
  for (let i = 0; i < fieldsArr.length; i++) {
7264
7569
  let field = fieldsArr[i];
7570
+ // Intermediate trace parts — assembled into effective only if value resolves.
7571
+ let traceType = null;
7572
+ let tracePart1 = null;
7573
+ let tracePart2 = null;
7265
7574
  // Bad data has it set to 'color' but expects the input to be a number.
7266
7575
  if (type == "number" && field.type == EValueType.Color) {
7267
7576
  field.type = EValueType.Input;
7268
7577
  }
7269
7578
  // Custom resolution.
7270
7579
  if (field.value instanceof Function) {
7580
+ traceType = "fn";
7271
7581
  value = field.value(data, tags);
7272
7582
  if (type == "number") {
7273
7583
  if (typeof value == "string" && value != "" && value != null && value != undefined) {
@@ -7301,6 +7611,8 @@ var Calculator;
7301
7611
  break;
7302
7612
  }
7303
7613
  value = field.value;
7614
+ traceType = "color";
7615
+ tracePart1 = encodeEffective(value);
7304
7616
  value = assertColor(value);
7305
7617
  if (value && type == "string") {
7306
7618
  value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
@@ -7310,10 +7622,17 @@ var Calculator;
7310
7622
  if (type === "number") {
7311
7623
  break;
7312
7624
  }
7313
- value = GetGradientValue(field.value, data, shouldRangesDefaultToMin);
7314
- value = assertColor(value);
7315
- if (value && type == "string") {
7316
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7625
+ {
7626
+ const gradTrace = _getGradientTrace(field.value, data, shouldRangesDefaultToMin);
7627
+ value = assertColor(gradTrace.result);
7628
+ traceType = "gradient";
7629
+ if (gradTrace.attrPath != null) {
7630
+ tracePart1 = encodeEffective(PathUtils.Wrap(gradTrace.attrPath));
7631
+ tracePart2 = encodeEffective(String(gradTrace.eValue));
7632
+ }
7633
+ if (value && type == "string") {
7634
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7635
+ }
7317
7636
  }
7318
7637
  break;
7319
7638
  case EValueType.RandomColor:
@@ -7322,6 +7641,7 @@ var Calculator;
7322
7641
  }
7323
7642
  value = Color.RandomColor();
7324
7643
  value = assertColor(value);
7644
+ traceType = "random";
7325
7645
  if (value && type == "string") {
7326
7646
  value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7327
7647
  }
@@ -7330,12 +7650,14 @@ var Calculator;
7330
7650
  if (type === "number") {
7331
7651
  break;
7332
7652
  }
7333
- for (let i = 0; i < tags.length; i++) {
7334
- const tag = tags[i];
7653
+ for (let ti = 0; ti < tags.length; ti++) {
7654
+ const tag = tags[ti];
7335
7655
  if (tag.Color) {
7336
7656
  value = Color.ColorFromStr(tag.Color);
7337
7657
  value = assertColor(value);
7338
7658
  if (value) {
7659
+ traceType = "tag";
7660
+ tracePart1 = encodeEffective(tag.Color);
7339
7661
  break;
7340
7662
  }
7341
7663
  }
@@ -7349,31 +7671,37 @@ var Calculator;
7349
7671
  // Eg: Result is a colour, a number, a string.
7350
7672
  // This means we first calculate the value, then validate it in the context of the desired type.
7351
7673
  case EValueType.Input:
7352
- value = GetInputValue(field.value, data);
7353
- if (value != null) {
7354
- if (type == "number") {
7355
- if (typeof value == "string" && value != "" && value != null && value != undefined) {
7356
- value = Number(value);
7357
- }
7358
- else if (typeof value != "number") {
7359
- value = null;
7360
- }
7361
- }
7362
- else if (type == "string") {
7363
- if (typeof value == "number") {
7364
- value = String(value);
7365
- }
7366
- else if (typeof value == "object") {
7367
- if (isColor(value)) {
7368
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7674
+ {
7675
+ const inputTemplate = String(field.value);
7676
+ value = GetInputValue(field.value, data);
7677
+ if (value != null) {
7678
+ traceType = "input";
7679
+ tracePart1 = encodeEffective(inputTemplate);
7680
+ tracePart2 = encodeEffective(String(value));
7681
+ if (type == "number") {
7682
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
7683
+ value = Number(value);
7369
7684
  }
7370
- else {
7685
+ else if (typeof value != "number") {
7371
7686
  value = null;
7372
7687
  }
7373
7688
  }
7374
- }
7375
- else if (type == "color") {
7376
- value = assertColor(value);
7689
+ else if (type == "string") {
7690
+ if (typeof value == "number") {
7691
+ value = String(value);
7692
+ }
7693
+ else if (typeof value == "object") {
7694
+ if (isColor(value)) {
7695
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7696
+ }
7697
+ else {
7698
+ value = null;
7699
+ }
7700
+ }
7701
+ }
7702
+ else if (type == "color") {
7703
+ value = assertColor(value);
7704
+ }
7377
7705
  }
7378
7706
  }
7379
7707
  break;
@@ -7381,31 +7709,39 @@ var Calculator;
7381
7709
  // Eg: mapping a value to a Client File ID, or a colour, or a number.
7382
7710
  // This means we first calculate the value, then validate it in the context of the desired type.
7383
7711
  case EValueType.Mapping:
7384
- value = GetMappingValue(field.value, data);
7385
- if (value != null) {
7386
- if (type == "number") {
7387
- if (typeof value == "string" && value != "" && value != null && value != undefined) {
7388
- value = Number(value);
7389
- }
7390
- else if (typeof value != "number") {
7391
- value = null;
7392
- }
7393
- }
7394
- else if (type == "string") {
7395
- if (typeof value == "number") {
7396
- value = String(value);
7712
+ {
7713
+ const mapTrace = _getMappingTrace(field.value, data);
7714
+ value = mapTrace.result;
7715
+ if (value != null) {
7716
+ traceType = "mapping";
7717
+ if (mapTrace.attrPath != null) {
7718
+ tracePart1 = encodeEffective(PathUtils.Wrap(mapTrace.attrPath));
7719
+ tracePart2 = encodeEffective(String(mapTrace.eValue));
7397
7720
  }
7398
- else if (typeof value == "object") {
7399
- if (isColor(value)) {
7400
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7721
+ if (type == "number") {
7722
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
7723
+ value = Number(value);
7401
7724
  }
7402
- else {
7725
+ else if (typeof value != "number") {
7403
7726
  value = null;
7404
7727
  }
7405
7728
  }
7406
- }
7407
- else if (type == "color") {
7408
- value = assertColor(typeof value === "number" ? String(value) : value);
7729
+ else if (type == "string") {
7730
+ if (typeof value == "number") {
7731
+ value = String(value);
7732
+ }
7733
+ else if (typeof value == "object") {
7734
+ if (isColor(value)) {
7735
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7736
+ }
7737
+ else {
7738
+ value = null;
7739
+ }
7740
+ }
7741
+ }
7742
+ else if (type == "color") {
7743
+ value = assertColor(typeof value === "number" ? String(value) : value);
7744
+ }
7409
7745
  }
7410
7746
  }
7411
7747
  break;
@@ -7429,11 +7765,34 @@ var Calculator;
7429
7765
  }
7430
7766
  }
7431
7767
  if (value != null) {
7768
+ if (traceType != null) {
7769
+ if (tracePart1 != null && tracePart2 != null) {
7770
+ computedEffective = `f${i}:${traceType}:${tracePart1}:${tracePart2}`;
7771
+ }
7772
+ else if (tracePart1 != null) {
7773
+ computedEffective = `f${i}:${traceType}:${tracePart1}`;
7774
+ }
7775
+ else {
7776
+ computedEffective = `f${i}:${traceType}`;
7777
+ }
7778
+ }
7432
7779
  break;
7433
7780
  }
7434
7781
  }
7435
- // Return the value or default.
7436
- return value != null ? value : defaultValue;
7782
+ return {
7783
+ value: value != null ? value : defaultValue,
7784
+ effective: value != null ? computedEffective : null
7785
+ };
7786
+ }
7787
+ Calculator.TraceCalculate = TraceCalculate;
7788
+ /**
7789
+ * Calculates a value-type 'T' based on given set of fields.
7790
+ * The supplied data + tags are fed into the calculation.
7791
+ * When a value fails to be calculated, the 'defaultValue' is returned.
7792
+ * If no 'defaultValue' is provided, then 'null' is returned.
7793
+ */
7794
+ function Calculate(params) {
7795
+ return TraceCalculate(params).value;
7437
7796
  }
7438
7797
  Calculator.Calculate = Calculate;
7439
7798
  /**
@@ -7445,13 +7804,7 @@ var Calculator;
7445
7804
  * @returns
7446
7805
  */
7447
7806
  function GetValue(fields, entity = {}, tags = []) {
7448
- return Calculate({
7449
- fields: fields,
7450
- data: entity,
7451
- defaultValue: null,
7452
- tags: tags,
7453
- type: "any"
7454
- });
7807
+ return TraceGetValue(fields, entity, tags).value;
7455
7808
  }
7456
7809
  Calculator.GetValue = GetValue;
7457
7810
  /**
@@ -7462,13 +7815,7 @@ var Calculator;
7462
7815
  * @param tags
7463
7816
  */
7464
7817
  function GetColor(fields, entity = {}, tags = []) {
7465
- return Calculate({
7466
- fields: fields,
7467
- data: entity,
7468
- defaultValue: null,
7469
- tags: tags,
7470
- type: "color"
7471
- });
7818
+ return TraceGetColor(fields, entity, tags).value;
7472
7819
  }
7473
7820
  Calculator.GetColor = GetColor;
7474
7821
  /**
@@ -7480,13 +7827,7 @@ var Calculator;
7480
7827
  * @returns
7481
7828
  */
7482
7829
  function GetNumber(fields, entity = {}, tags = []) {
7483
- return Calculate({
7484
- fields: fields,
7485
- data: entity,
7486
- defaultValue: null,
7487
- tags: tags,
7488
- type: "number"
7489
- });
7830
+ return TraceGetNumber(fields, entity, tags).value;
7490
7831
  }
7491
7832
  Calculator.GetNumber = GetNumber;
7492
7833
  /**
@@ -7498,15 +7839,61 @@ var Calculator;
7498
7839
  * @returns
7499
7840
  */
7500
7841
  function GetString(fields, entity = {}, tags = []) {
7501
- return Calculate({
7502
- fields: fields,
7842
+ return TraceGetString(fields, entity, tags).value;
7843
+ }
7844
+ Calculator.GetString = GetString;
7845
+ /**
7846
+ * Like GetValue, but also returns 'effective' describing how the value was derived.
7847
+ */
7848
+ function TraceGetValue(fields, entity = {}, tags = []) {
7849
+ return TraceCalculate({
7850
+ fields,
7503
7851
  data: entity,
7504
7852
  defaultValue: null,
7505
- tags: tags,
7853
+ tags,
7854
+ type: "any"
7855
+ });
7856
+ }
7857
+ Calculator.TraceGetValue = TraceGetValue;
7858
+ /**
7859
+ * Like GetColor, but also returns 'effective' describing how the color was derived.
7860
+ */
7861
+ function TraceGetColor(fields, entity = {}, tags = []) {
7862
+ return TraceCalculate({
7863
+ fields,
7864
+ data: entity,
7865
+ defaultValue: null,
7866
+ tags,
7867
+ type: "color"
7868
+ });
7869
+ }
7870
+ Calculator.TraceGetColor = TraceGetColor;
7871
+ /**
7872
+ * Like GetNumber, but also returns 'effective' describing how the number was derived.
7873
+ */
7874
+ function TraceGetNumber(fields, entity = {}, tags = []) {
7875
+ return TraceCalculate({
7876
+ fields,
7877
+ data: entity,
7878
+ defaultValue: null,
7879
+ tags,
7880
+ type: "number"
7881
+ });
7882
+ }
7883
+ Calculator.TraceGetNumber = TraceGetNumber;
7884
+ /**
7885
+ * Like GetString, but also returns 'effective' describing how the string was derived.
7886
+ */
7887
+ function TraceGetString(fields, entity = {}, tags = []) {
7888
+ return TraceCalculate({
7889
+ fields,
7890
+ data: entity,
7891
+ defaultValue: null,
7892
+ tags,
7506
7893
  type: "string"
7507
7894
  });
7508
7895
  }
7509
- Calculator.GetString = GetString;
7896
+ Calculator.TraceGetString = TraceGetString;
7510
7897
  /**
7511
7898
  * Calculates a mapping value. This can return any value type.
7512
7899
  * It is intended to be parsed and validated within a value-type context. Eg: GetColor, GetNumber, GetString.
@@ -7515,114 +7902,7 @@ var Calculator;
7515
7902
  * @returns
7516
7903
  */
7517
7904
  function GetMappingValue(value, entity) {
7518
- const attrPaths = parseLegacyPath(value.field);
7519
- for (let i = 0; i < attrPaths.length; i++) {
7520
- const attrPath = attrPaths[i];
7521
- let eValue = Entity.GetValue({
7522
- entity: entity,
7523
- path: attrPath
7524
- });
7525
- let isValueNum = !isNaN(+eValue);
7526
- if (eValue == null) {
7527
- isValueNum = false;
7528
- }
7529
- for (let i = 0; i < value.values.length; i++) {
7530
- const option = value.values[i];
7531
- const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
7532
- // Check each field value in the array.
7533
- for (let j = 0; j < fieldValues.length; j++) {
7534
- let mapValue = fieldValues[j];
7535
- // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
7536
- // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
7537
- if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
7538
- try {
7539
- let jsEval = mapValue.replace("JS:", "").trim();
7540
- const attrPathStr = PathUtils.Wrap(attrPath);
7541
- jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
7542
- jsEval = BruceVariable.SwapValues({
7543
- str: jsEval,
7544
- entity: entity
7545
- });
7546
- // https://rollupjs.org/guide/en/#avoiding-eval
7547
- // This stops eval warning.
7548
- const eval2 = eval;
7549
- mapValue = eval2(jsEval);
7550
- // We currently expect eval to return a validity bool.
7551
- // So it either matches and we return it, or it doesn't and we continue.
7552
- if (mapValue) {
7553
- return option.appliedValue;
7554
- }
7555
- else {
7556
- continue;
7557
- }
7558
- }
7559
- catch (exception) {
7560
- const e = exception;
7561
- let suppress = false;
7562
- if (e && typeof e == "object") {
7563
- const msg = e.message;
7564
- suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
7565
- }
7566
- if (!suppress) {
7567
- console.error(e);
7568
- }
7569
- // Eval failed, therefor not a valid mapping-row.
7570
- continue;
7571
- }
7572
- }
7573
- let isMapValueNum = !isNaN(+mapValue);
7574
- if (isMapValueNum == null) {
7575
- isMapValueNum = false;
7576
- }
7577
- if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
7578
- if (+mapValue == +eValue) {
7579
- return option.appliedValue;
7580
- }
7581
- const mapSplit = mapValue.split("-");
7582
- if (mapSplit.length == 2) {
7583
- const min = mapSplit[0];
7584
- const max = mapSplit[1];
7585
- if (min != "") {
7586
- if (+eValue < +min) {
7587
- continue;
7588
- }
7589
- }
7590
- if (max != "") {
7591
- if (+eValue > +max) {
7592
- continue;
7593
- }
7594
- }
7595
- if (min == "" && max == "") {
7596
- continue;
7597
- }
7598
- return option.appliedValue;
7599
- }
7600
- }
7601
- else {
7602
- if (mapValue == eValue) {
7603
- return option.appliedValue;
7604
- }
7605
- // Case where Entity value is a boolean but the mapping value is a string.
7606
- // Common as mapping value is typically a user-entered string.
7607
- else if (typeof eValue === "boolean" && typeof mapValue === "string") {
7608
- const eValueStr = eValue ? "true" : "false";
7609
- if (mapValue.toLowerCase() == eValueStr) {
7610
- return option.appliedValue;
7611
- }
7612
- }
7613
- // Handling possible case where the opposite is true.
7614
- // Have not seen this happen yet, but preparing for any future cases.
7615
- else if (typeof mapValue === "boolean" && typeof eValue === "string") {
7616
- const mapValueStr = mapValue ? "true" : "false";
7617
- if (mapValueStr == eValue.toLowerCase()) {
7618
- return option.appliedValue;
7619
- }
7620
- }
7621
- }
7622
- }
7623
- }
7624
- }
7625
- return null;
7905
+ return _getMappingTrace(value, entity).result;
7626
7906
  }
7627
7907
  Calculator.GetMappingValue = GetMappingValue;
7628
7908
  /**
@@ -7635,47 +7915,7 @@ var Calculator;
7635
7915
  * @returns
7636
7916
  */
7637
7917
  function GetGradientValue(value, entity, defaultToMin) {
7638
- const min = +value.points[0].position;
7639
- const max = +value.points[value.points.length - 1].position;
7640
- const attrPaths = parseLegacyPath(value.field);
7641
- for (let i = 0; i < attrPaths.length; i++) {
7642
- const attrPath = attrPaths[i];
7643
- let eValue = Entity.GetValue({
7644
- entity: entity,
7645
- path: attrPath
7646
- });
7647
- if (typeof eValue == "string") {
7648
- eValue = Number(eValue);
7649
- }
7650
- if ((!eValue && eValue != 0) || isNaN(eValue)) {
7651
- continue;
7652
- }
7653
- if (eValue >= max) {
7654
- return Color.ColorFromStr(value.points[value.points.length - 1].color);
7655
- }
7656
- else if (eValue <= min) {
7657
- return Color.ColorFromStr(value.points[0].color);
7658
- }
7659
- for (let i = 0; i < value.points.length - 1; i++) {
7660
- const pointA = value.points[i];
7661
- const pointB = value.points[i + 1];
7662
- if (eValue >= pointA.position && eValue <= pointB.position) {
7663
- if (pointA.position == pointB.position) {
7664
- return Color.ColorFromStr(pointA.color);
7665
- }
7666
- const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
7667
- const colorA = Color.ColorFromStr(pointA.color);
7668
- const colorB = Color.ColorFromStr(pointB.color);
7669
- return {
7670
- red: colorA.red + (colorB.red - colorA.red) * distance,
7671
- green: colorA.green + (colorB.green - colorA.green) * distance,
7672
- blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
7673
- alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
7674
- };
7675
- }
7676
- }
7677
- }
7678
- return Color.ColorFromStr(value.points[0].color);
7918
+ return _getGradientTrace(value, entity, defaultToMin).result;
7679
7919
  }
7680
7920
  Calculator.GetGradientValue = GetGradientValue;
7681
7921
  /**
@@ -19019,7 +19259,7 @@ var UrlUtils;
19019
19259
  })(UrlUtils || (UrlUtils = {}));
19020
19260
 
19021
19261
  // This is updated with the package.json version on build.
19022
- const VERSION = "7.1.53";
19262
+ const VERSION = "7.1.55";
19023
19263
 
19024
- export { VERSION, Account, AccountConcept, AccountFeatures, AccountInvite, AccountLimits, AccountTemplate, AccountType, AnnDocument, AbstractApi, Api, ApiGetters, BruceApi, GlobalApi, GuardianApi, Assembly, Calculator, ChangeSet, ClientFile, Bounds, BruceEvent, BruceVariable, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, GeoJson, Geometry, LRUCache, UTC, CustomForm, DashboardView, DataFeed, DataLab, DataLabGroup, DataSource, DataTransform, Comment, Entity, EntityAttachment, EntityAttachmentType, EntityAttribute, EntityComment, EntityCoords, EntityHistoricData, EntityLink, EntityLod, EntityLodCategory, EntityRelation, EntityRelationType, EntitySource, EntityTableView, EntityTag, EntityType, EntityTypeTrigger, ENVIRONMENT, ExportBrz, ExportUsd, ImportAssembly, ImportCad, ImportCsv, ImportGeoJson, ImportJson, ImportKml, ImportLcc, ImportedFile, Uploader, Markup, NAVIGATOR_CHAT_EVENT_ENTITY_HIGHLIGHT_APPLIED, NAVIGATOR_CHAT_EVENT_SCENE_CONTEXT_PREFETCHED, NavigatorChatClient, NavigatorMcpWebSocketClient, Plugin, ProgramKey, MenuItem, ProjectView, ProjectViewBookmark, ProjectViewBookmarkGroup, ProjectViewLegacy, ProjectViewLegacyBookmark, ProjectViewLegacyTile, ProjectViewTile, ZoomControl, Scenario, HostingLocation, MessageBroker, PendingAction, RecordChangeFeed, Style, Tileset, Tracking, Permission, Session, User, UserGroup, UserMfaMethod, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils };
19264
+ export { VERSION, Account, AccountAudit, AccountConcept, AccountFeatures, AccountInvite, AccountLimits, AccountTemplate, AccountType, AnnDocument, AbstractApi, Api, ApiGetters, BruceApi, GlobalApi, GuardianApi, Assembly, Calculator, ChangeSet, ClientFile, Bounds, BruceEvent, BruceVariable, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, GeoJson, Geometry, LRUCache, UTC, CustomForm, DashboardView, DataFeed, DataLab, DataLabGroup, DataSource, DataTransform, Comment, Entity, EntityAttachment, EntityAttachmentType, EntityAttribute, EntityComment, EntityCoords, EntityHistoricData, EntityLink, EntityLod, EntityLodCategory, EntityRelation, EntityRelationType, EntitySource, EntityTableView, EntityTag, EntityType, EntityTypeTrigger, ENVIRONMENT, ExportBrz, ExportUsd, ImportAssembly, ImportCad, ImportCsv, ImportGeoJson, ImportJson, ImportKml, ImportLcc, ImportedFile, Uploader, Markup, NAVIGATOR_CHAT_EVENT_ENTITY_HIGHLIGHT_APPLIED, NAVIGATOR_CHAT_EVENT_SCENE_CONTEXT_PREFETCHED, NavigatorChatClient, NavigatorMcpWebSocketClient, Plugin, ProgramKey, MenuItem, ProjectView, ProjectViewBookmark, ProjectViewBookmarkGroup, ProjectViewLegacy, ProjectViewLegacyBookmark, ProjectViewLegacyTile, ProjectViewTile, ZoomControl, Scenario, HostingLocation, MessageBroker, PendingAction, RecordChangeFeed, Style, Tileset, Tracking, Permission, Session, User, UserGroup, UserMfaMethod, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils };
19025
19265
  //# sourceMappingURL=bruce-models.es5.js.map