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.
@@ -2707,6 +2707,88 @@
2707
2707
  Account.GetDbRegionListCacheKey = GetDbRegionListCacheKey;
2708
2708
  })(exports.Account || (exports.Account = {}));
2709
2709
 
2710
+ (function (AccountAudit) {
2711
+ let EType;
2712
+ (function (EType) {
2713
+ EType["LOG"] = "L";
2714
+ EType["CREATE"] = "C";
2715
+ EType["UPDATE"] = "U";
2716
+ EType["DELETE"] = "D";
2717
+ })(EType = AccountAudit.EType || (AccountAudit.EType = {}));
2718
+ let ESeverity;
2719
+ (function (ESeverity) {
2720
+ ESeverity["DEBUG"] = "D";
2721
+ ESeverity["INFO"] = "I";
2722
+ ESeverity["WARN"] = "W";
2723
+ ESeverity["ERROR"] = "E";
2724
+ })(ESeverity = AccountAudit.ESeverity || (AccountAudit.ESeverity = {}));
2725
+ let EDetailLevel;
2726
+ (function (EDetailLevel) {
2727
+ EDetailLevel["SUMMARY"] = "summary";
2728
+ EDetailLevel["FULL"] = "full";
2729
+ })(EDetailLevel = AccountAudit.EDetailLevel || (AccountAudit.EDetailLevel = {}));
2730
+ let EAction;
2731
+ (function (EAction) {
2732
+ EAction["CREATED"] = "Created";
2733
+ EAction["UPDATED"] = "Updated";
2734
+ EAction["DELETED"] = "Deleted";
2735
+ })(EAction = AccountAudit.EAction || (AccountAudit.EAction = {}));
2736
+ let EOrderBy;
2737
+ (function (EOrderBy) {
2738
+ EOrderBy["ID"] = "ID";
2739
+ EOrderBy["LOGGED"] = "Logged";
2740
+ EOrderBy["CREATED"] = "Created";
2741
+ EOrderBy["CREATED_DATE"] = "CreatedDate";
2742
+ EOrderBy["SEVERITY"] = "Severity";
2743
+ EOrderBy["TYPE"] = "Type";
2744
+ EOrderBy["ACTION"] = "Action";
2745
+ EOrderBy["MESSAGE"] = "Message";
2746
+ EOrderBy["CONCEPT"] = "Concept";
2747
+ EOrderBy["SCOPE"] = "Scope";
2748
+ EOrderBy["USER_ID"] = "User.ID";
2749
+ })(EOrderBy = AccountAudit.EOrderBy || (AccountAudit.EOrderBy = {}));
2750
+ function GetConceptList(params) {
2751
+ return __awaiter(this, void 0, void 0, function* () {
2752
+ let { api, req: reqParams, concept, pageSize, pageIndex, lastSeenId, search, orderBy, sortOrder, recordId, detailLevel } = params;
2753
+ if (!api) {
2754
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
2755
+ }
2756
+ if (!concept) {
2757
+ throw new Error("Concept is required.");
2758
+ }
2759
+ const urlParams = new URLSearchParams();
2760
+ if (pageSize != null) {
2761
+ urlParams.append("PageSize", String(pageSize));
2762
+ }
2763
+ if (pageIndex != null) {
2764
+ urlParams.append("PageIndex", String(pageIndex));
2765
+ }
2766
+ if (lastSeenId != null) {
2767
+ urlParams.append("LastSeenID", String(lastSeenId));
2768
+ }
2769
+ if (search) {
2770
+ urlParams.append("Search", search);
2771
+ }
2772
+ if (orderBy) {
2773
+ urlParams.append("OrderBy", orderBy);
2774
+ }
2775
+ if (sortOrder) {
2776
+ urlParams.append("SortOrder", sortOrder);
2777
+ }
2778
+ if (recordId) {
2779
+ urlParams.append("RecordID", recordId);
2780
+ }
2781
+ if (detailLevel) {
2782
+ urlParams.append("DetailLevel", detailLevel);
2783
+ }
2784
+ const query = urlParams.toString();
2785
+ const route = `v3/accountAudits/concept/${exports.Api.Encode(String(concept))}`;
2786
+ return api.GET(query ? `${route}?${query}` : route, exports.Api.PrepReqParams(reqParams));
2787
+ });
2788
+ }
2789
+ AccountAudit.GetConceptList = GetConceptList;
2790
+ })(exports.AccountAudit || (exports.AccountAudit = {}));
2791
+
2710
2792
  (function (AccountFeatures) {
2711
2793
  let EFeature;
2712
2794
  (function (EFeature) {
@@ -7111,12 +7193,234 @@
7111
7193
  EValueType[EValueType["RandomColor"] = 5] = "RandomColor";
7112
7194
  })(EValueType = Calculator.EValueType || (Calculator.EValueType = {}));
7113
7195
  /**
7114
- * Calculates a value-type 'T' based on given set of fields.
7115
- * The supplied data + tags are fed into the calculation.
7116
- * When a value fails to be calculated, the 'defaultValue' is returned.
7117
- * If no 'defaultValue' is provided, then 'null' is returned.
7196
+ * Decodes an effective string produced by TraceCalculate back into a structured object.
7197
+ * Returns null if the string is null, empty, or does not match the expected format.
7118
7198
  */
7119
- function Calculate(params) {
7199
+ function DecodeEffective(effective) {
7200
+ if (!effective) {
7201
+ return null;
7202
+ }
7203
+ // Format: f{index}:{type}[:{part1}[:{part2}]]
7204
+ const match = effective.match(/^f(\d+):([^:]+)(?::([^:]+)(?::([^:]+))?)?$/);
7205
+ if (!match) {
7206
+ return null;
7207
+ }
7208
+ const fieldIndex = parseInt(match[1], 10);
7209
+ const type = match[2];
7210
+ const part1 = match[3] != null ? decodeEffective(match[3]) : null;
7211
+ const part2 = match[4] != null ? decodeEffective(match[4]) : null;
7212
+ const base = { type, fieldIndex };
7213
+ switch (type) {
7214
+ case "color":
7215
+ if (part1 == null) {
7216
+ return null;
7217
+ }
7218
+ return Object.assign(Object.assign({}, base), { colorStr: part1 });
7219
+ case "gradient":
7220
+ case "mapping":
7221
+ return Object.assign(Object.assign(Object.assign({}, base), (part1 != null && { path: part1 })), (part2 != null && { entityValue: part2 }));
7222
+ case "input":
7223
+ if (part1 == null || part2 == null) {
7224
+ return null;
7225
+ }
7226
+ return Object.assign(Object.assign({}, base), { template: part1, resolvedValue: part2 });
7227
+ case "tag":
7228
+ if (part1 == null) {
7229
+ return null;
7230
+ }
7231
+ return Object.assign(Object.assign({}, base), { tagColor: part1 });
7232
+ case "random":
7233
+ case "fn":
7234
+ return base;
7235
+ default:
7236
+ return null;
7237
+ }
7238
+ }
7239
+ Calculator.DecodeEffective = DecodeEffective;
7240
+ function encodeEffective(str) {
7241
+ const s = String(str == null ? "" : str);
7242
+ try {
7243
+ if (typeof Buffer !== "undefined") {
7244
+ return Buffer.from(s).toString("base64").replace(/=+$/, "");
7245
+ }
7246
+ // Browser fallback
7247
+ return btoa(s).replace(/=+$/, "");
7248
+ }
7249
+ catch (e) {
7250
+ return encodeURIComponent(s);
7251
+ }
7252
+ }
7253
+ function decodeEffective(encoded) {
7254
+ try {
7255
+ if (typeof Buffer !== "undefined") {
7256
+ return Buffer.from(encoded, "base64").toString("utf8");
7257
+ }
7258
+ return atob(encoded);
7259
+ }
7260
+ catch (e) {
7261
+ return decodeURIComponent(encoded);
7262
+ }
7263
+ }
7264
+ function _getMappingTrace(value, entity) {
7265
+ const attrPaths = parseLegacyPath(value.field);
7266
+ for (let i = 0; i < attrPaths.length; i++) {
7267
+ const attrPath = attrPaths[i];
7268
+ let eValue = exports.Entity.GetValue({
7269
+ entity: entity,
7270
+ path: attrPath
7271
+ });
7272
+ let isValueNum = !isNaN(+eValue);
7273
+ if (eValue == null) {
7274
+ isValueNum = false;
7275
+ }
7276
+ for (let j = 0; j < value.values.length; j++) {
7277
+ const option = value.values[j];
7278
+ const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
7279
+ for (let k = 0; k < fieldValues.length; k++) {
7280
+ let mapValue = fieldValues[k];
7281
+ // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
7282
+ // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
7283
+ if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
7284
+ try {
7285
+ let jsEval = mapValue.replace("JS:", "").trim();
7286
+ const attrPathStr = exports.PathUtils.Wrap(attrPath);
7287
+ jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
7288
+ jsEval = exports.BruceVariable.SwapValues({
7289
+ str: jsEval,
7290
+ entity: entity
7291
+ });
7292
+ // https://rollupjs.org/guide/en/#avoiding-eval
7293
+ // This stops eval warning.
7294
+ const eval2 = eval;
7295
+ mapValue = eval2(jsEval);
7296
+ if (mapValue) {
7297
+ return { result: option.appliedValue, attrPath, eValue };
7298
+ }
7299
+ else {
7300
+ continue;
7301
+ }
7302
+ }
7303
+ catch (exception) {
7304
+ const e = exception;
7305
+ let suppress = false;
7306
+ if (e && typeof e == "object") {
7307
+ const msg = e.message;
7308
+ suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
7309
+ }
7310
+ if (!suppress) {
7311
+ console.error(e);
7312
+ }
7313
+ // Eval failed, therefor not a valid mapping-row.
7314
+ continue;
7315
+ }
7316
+ }
7317
+ let isMapValueNum = !isNaN(+mapValue);
7318
+ if (isMapValueNum == null) {
7319
+ isMapValueNum = false;
7320
+ }
7321
+ if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
7322
+ if (+mapValue == +eValue) {
7323
+ return { result: option.appliedValue, attrPath, eValue };
7324
+ }
7325
+ const mapSplit = mapValue.split("-");
7326
+ if (mapSplit.length == 2) {
7327
+ const min = mapSplit[0];
7328
+ const max = mapSplit[1];
7329
+ if (min != "") {
7330
+ if (+eValue < +min) {
7331
+ continue;
7332
+ }
7333
+ }
7334
+ if (max != "") {
7335
+ if (+eValue > +max) {
7336
+ continue;
7337
+ }
7338
+ }
7339
+ if (min == "" && max == "") {
7340
+ continue;
7341
+ }
7342
+ return { result: option.appliedValue, attrPath, eValue };
7343
+ }
7344
+ }
7345
+ else {
7346
+ if (mapValue == eValue) {
7347
+ return { result: option.appliedValue, attrPath, eValue };
7348
+ }
7349
+ // Case where Entity value is a boolean but the mapping value is a string.
7350
+ // Common as mapping value is typically a user-entered string.
7351
+ else if (typeof eValue === "boolean" && typeof mapValue === "string") {
7352
+ const eValueStr = eValue ? "true" : "false";
7353
+ if (mapValue.toLowerCase() == eValueStr) {
7354
+ return { result: option.appliedValue, attrPath, eValue };
7355
+ }
7356
+ }
7357
+ // Handling possible case where the opposite is true.
7358
+ // Have not seen this happen yet, but preparing for any future cases.
7359
+ else if (typeof mapValue === "boolean" && typeof eValue === "string") {
7360
+ const mapValueStr = mapValue ? "true" : "false";
7361
+ if (mapValueStr == eValue.toLowerCase()) {
7362
+ return { result: option.appliedValue, attrPath, eValue };
7363
+ }
7364
+ }
7365
+ }
7366
+ }
7367
+ }
7368
+ }
7369
+ return { result: null, attrPath: null, eValue: null };
7370
+ }
7371
+ function _getGradientTrace(value, entity, defaultToMin) {
7372
+ const min = +value.points[0].position;
7373
+ const max = +value.points[value.points.length - 1].position;
7374
+ const attrPaths = parseLegacyPath(value.field);
7375
+ for (let i = 0; i < attrPaths.length; i++) {
7376
+ const attrPath = attrPaths[i];
7377
+ let eValue = exports.Entity.GetValue({
7378
+ entity: entity,
7379
+ path: attrPath
7380
+ });
7381
+ if (typeof eValue == "string") {
7382
+ eValue = Number(eValue);
7383
+ }
7384
+ if ((!eValue && eValue != 0) || isNaN(eValue)) {
7385
+ continue;
7386
+ }
7387
+ if (eValue >= max) {
7388
+ return { result: exports.Color.ColorFromStr(value.points[value.points.length - 1].color), attrPath, eValue };
7389
+ }
7390
+ else if (eValue <= min) {
7391
+ return { result: exports.Color.ColorFromStr(value.points[0].color), attrPath, eValue };
7392
+ }
7393
+ for (let j = 0; j < value.points.length - 1; j++) {
7394
+ const pointA = value.points[j];
7395
+ const pointB = value.points[j + 1];
7396
+ if (eValue >= pointA.position && eValue <= pointB.position) {
7397
+ if (pointA.position == pointB.position) {
7398
+ return { result: exports.Color.ColorFromStr(pointA.color), attrPath, eValue };
7399
+ }
7400
+ const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
7401
+ const colorA = exports.Color.ColorFromStr(pointA.color);
7402
+ const colorB = exports.Color.ColorFromStr(pointB.color);
7403
+ return {
7404
+ result: {
7405
+ red: colorA.red + (colorB.red - colorA.red) * distance,
7406
+ green: colorA.green + (colorB.green - colorA.green) * distance,
7407
+ blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
7408
+ alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
7409
+ },
7410
+ attrPath,
7411
+ eValue
7412
+ };
7413
+ }
7414
+ }
7415
+ }
7416
+ // Fallback to min (static, no data path resolved).
7417
+ return { result: exports.Color.ColorFromStr(value.points[0].color), attrPath: null, eValue: null };
7418
+ }
7419
+ /**
7420
+ * Like Calculate, but also returns an 'effective' key describing how the value
7421
+ * was derived. See ITraceResult for the key format.
7422
+ */
7423
+ function TraceCalculate(params) {
7120
7424
  let { fields, tags, data, defaultValue, type } = params;
7121
7425
  // If params doesn't include a defaultValue, use null.
7122
7426
  // Though passing in undefined is valid!
@@ -7124,7 +7428,7 @@
7124
7428
  defaultValue = null;
7125
7429
  }
7126
7430
  if (fields == null) {
7127
- return defaultValue;
7431
+ return { value: defaultValue, effective: null };
7128
7432
  }
7129
7433
  if (data == null || typeof data != "object") {
7130
7434
  data = {};
@@ -7169,16 +7473,21 @@
7169
7473
  }
7170
7474
  return false;
7171
7475
  };
7172
- // Calculate the value.
7173
7476
  let value = null;
7477
+ let computedEffective = null;
7174
7478
  for (let i = 0; i < fieldsArr.length; i++) {
7175
7479
  let field = fieldsArr[i];
7480
+ // Intermediate trace parts — assembled into effective only if value resolves.
7481
+ let traceType = null;
7482
+ let tracePart1 = null;
7483
+ let tracePart2 = null;
7176
7484
  // Bad data has it set to 'color' but expects the input to be a number.
7177
7485
  if (type == "number" && field.type == EValueType.Color) {
7178
7486
  field.type = EValueType.Input;
7179
7487
  }
7180
7488
  // Custom resolution.
7181
7489
  if (field.value instanceof Function) {
7490
+ traceType = "fn";
7182
7491
  value = field.value(data, tags);
7183
7492
  if (type == "number") {
7184
7493
  if (typeof value == "string" && value != "" && value != null && value != undefined) {
@@ -7212,6 +7521,8 @@
7212
7521
  break;
7213
7522
  }
7214
7523
  value = field.value;
7524
+ traceType = "color";
7525
+ tracePart1 = encodeEffective(value);
7215
7526
  value = assertColor(value);
7216
7527
  if (value && type == "string") {
7217
7528
  value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
@@ -7221,10 +7532,17 @@
7221
7532
  if (type === "number") {
7222
7533
  break;
7223
7534
  }
7224
- value = GetGradientValue(field.value, data, shouldRangesDefaultToMin);
7225
- value = assertColor(value);
7226
- if (value && type == "string") {
7227
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7535
+ {
7536
+ const gradTrace = _getGradientTrace(field.value, data, shouldRangesDefaultToMin);
7537
+ value = assertColor(gradTrace.result);
7538
+ traceType = "gradient";
7539
+ if (gradTrace.attrPath != null) {
7540
+ tracePart1 = encodeEffective(exports.PathUtils.Wrap(gradTrace.attrPath));
7541
+ tracePart2 = encodeEffective(String(gradTrace.eValue));
7542
+ }
7543
+ if (value && type == "string") {
7544
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7545
+ }
7228
7546
  }
7229
7547
  break;
7230
7548
  case EValueType.RandomColor:
@@ -7233,6 +7551,7 @@
7233
7551
  }
7234
7552
  value = exports.Color.RandomColor();
7235
7553
  value = assertColor(value);
7554
+ traceType = "random";
7236
7555
  if (value && type == "string") {
7237
7556
  value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7238
7557
  }
@@ -7241,12 +7560,14 @@
7241
7560
  if (type === "number") {
7242
7561
  break;
7243
7562
  }
7244
- for (let i = 0; i < tags.length; i++) {
7245
- const tag = tags[i];
7563
+ for (let ti = 0; ti < tags.length; ti++) {
7564
+ const tag = tags[ti];
7246
7565
  if (tag.Color) {
7247
7566
  value = exports.Color.ColorFromStr(tag.Color);
7248
7567
  value = assertColor(value);
7249
7568
  if (value) {
7569
+ traceType = "tag";
7570
+ tracePart1 = encodeEffective(tag.Color);
7250
7571
  break;
7251
7572
  }
7252
7573
  }
@@ -7260,31 +7581,37 @@
7260
7581
  // Eg: Result is a colour, a number, a string.
7261
7582
  // This means we first calculate the value, then validate it in the context of the desired type.
7262
7583
  case EValueType.Input:
7263
- value = GetInputValue(field.value, data);
7264
- if (value != null) {
7265
- if (type == "number") {
7266
- if (typeof value == "string" && value != "" && value != null && value != undefined) {
7267
- value = Number(value);
7268
- }
7269
- else if (typeof value != "number") {
7270
- value = null;
7271
- }
7272
- }
7273
- else if (type == "string") {
7274
- if (typeof value == "number") {
7275
- value = String(value);
7276
- }
7277
- else if (typeof value == "object") {
7278
- if (isColor(value)) {
7279
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7584
+ {
7585
+ const inputTemplate = String(field.value);
7586
+ value = GetInputValue(field.value, data);
7587
+ if (value != null) {
7588
+ traceType = "input";
7589
+ tracePart1 = encodeEffective(inputTemplate);
7590
+ tracePart2 = encodeEffective(String(value));
7591
+ if (type == "number") {
7592
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
7593
+ value = Number(value);
7280
7594
  }
7281
- else {
7595
+ else if (typeof value != "number") {
7282
7596
  value = null;
7283
7597
  }
7284
7598
  }
7285
- }
7286
- else if (type == "color") {
7287
- value = assertColor(value);
7599
+ else if (type == "string") {
7600
+ if (typeof value == "number") {
7601
+ value = String(value);
7602
+ }
7603
+ else if (typeof value == "object") {
7604
+ if (isColor(value)) {
7605
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7606
+ }
7607
+ else {
7608
+ value = null;
7609
+ }
7610
+ }
7611
+ }
7612
+ else if (type == "color") {
7613
+ value = assertColor(value);
7614
+ }
7288
7615
  }
7289
7616
  }
7290
7617
  break;
@@ -7292,31 +7619,39 @@
7292
7619
  // Eg: mapping a value to a Client File ID, or a colour, or a number.
7293
7620
  // This means we first calculate the value, then validate it in the context of the desired type.
7294
7621
  case EValueType.Mapping:
7295
- value = GetMappingValue(field.value, data);
7296
- if (value != null) {
7297
- if (type == "number") {
7298
- if (typeof value == "string" && value != "" && value != null && value != undefined) {
7299
- value = Number(value);
7300
- }
7301
- else if (typeof value != "number") {
7302
- value = null;
7303
- }
7304
- }
7305
- else if (type == "string") {
7306
- if (typeof value == "number") {
7307
- value = String(value);
7622
+ {
7623
+ const mapTrace = _getMappingTrace(field.value, data);
7624
+ value = mapTrace.result;
7625
+ if (value != null) {
7626
+ traceType = "mapping";
7627
+ if (mapTrace.attrPath != null) {
7628
+ tracePart1 = encodeEffective(exports.PathUtils.Wrap(mapTrace.attrPath));
7629
+ tracePart2 = encodeEffective(String(mapTrace.eValue));
7308
7630
  }
7309
- else if (typeof value == "object") {
7310
- if (isColor(value)) {
7311
- value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7631
+ if (type == "number") {
7632
+ if (typeof value == "string" && value != "" && value != null && value != undefined) {
7633
+ value = Number(value);
7312
7634
  }
7313
- else {
7635
+ else if (typeof value != "number") {
7314
7636
  value = null;
7315
7637
  }
7316
7638
  }
7317
- }
7318
- else if (type == "color") {
7319
- value = assertColor(typeof value === "number" ? String(value) : value);
7639
+ else if (type == "string") {
7640
+ if (typeof value == "number") {
7641
+ value = String(value);
7642
+ }
7643
+ else if (typeof value == "object") {
7644
+ if (isColor(value)) {
7645
+ value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
7646
+ }
7647
+ else {
7648
+ value = null;
7649
+ }
7650
+ }
7651
+ }
7652
+ else if (type == "color") {
7653
+ value = assertColor(typeof value === "number" ? String(value) : value);
7654
+ }
7320
7655
  }
7321
7656
  }
7322
7657
  break;
@@ -7340,11 +7675,34 @@
7340
7675
  }
7341
7676
  }
7342
7677
  if (value != null) {
7678
+ if (traceType != null) {
7679
+ if (tracePart1 != null && tracePart2 != null) {
7680
+ computedEffective = `f${i}:${traceType}:${tracePart1}:${tracePart2}`;
7681
+ }
7682
+ else if (tracePart1 != null) {
7683
+ computedEffective = `f${i}:${traceType}:${tracePart1}`;
7684
+ }
7685
+ else {
7686
+ computedEffective = `f${i}:${traceType}`;
7687
+ }
7688
+ }
7343
7689
  break;
7344
7690
  }
7345
7691
  }
7346
- // Return the value or default.
7347
- return value != null ? value : defaultValue;
7692
+ return {
7693
+ value: value != null ? value : defaultValue,
7694
+ effective: value != null ? computedEffective : null
7695
+ };
7696
+ }
7697
+ Calculator.TraceCalculate = TraceCalculate;
7698
+ /**
7699
+ * Calculates a value-type 'T' based on given set of fields.
7700
+ * The supplied data + tags are fed into the calculation.
7701
+ * When a value fails to be calculated, the 'defaultValue' is returned.
7702
+ * If no 'defaultValue' is provided, then 'null' is returned.
7703
+ */
7704
+ function Calculate(params) {
7705
+ return TraceCalculate(params).value;
7348
7706
  }
7349
7707
  Calculator.Calculate = Calculate;
7350
7708
  /**
@@ -7356,13 +7714,7 @@
7356
7714
  * @returns
7357
7715
  */
7358
7716
  function GetValue(fields, entity = {}, tags = []) {
7359
- return Calculate({
7360
- fields: fields,
7361
- data: entity,
7362
- defaultValue: null,
7363
- tags: tags,
7364
- type: "any"
7365
- });
7717
+ return TraceGetValue(fields, entity, tags).value;
7366
7718
  }
7367
7719
  Calculator.GetValue = GetValue;
7368
7720
  /**
@@ -7373,13 +7725,7 @@
7373
7725
  * @param tags
7374
7726
  */
7375
7727
  function GetColor(fields, entity = {}, tags = []) {
7376
- return Calculate({
7377
- fields: fields,
7378
- data: entity,
7379
- defaultValue: null,
7380
- tags: tags,
7381
- type: "color"
7382
- });
7728
+ return TraceGetColor(fields, entity, tags).value;
7383
7729
  }
7384
7730
  Calculator.GetColor = GetColor;
7385
7731
  /**
@@ -7391,13 +7737,7 @@
7391
7737
  * @returns
7392
7738
  */
7393
7739
  function GetNumber(fields, entity = {}, tags = []) {
7394
- return Calculate({
7395
- fields: fields,
7396
- data: entity,
7397
- defaultValue: null,
7398
- tags: tags,
7399
- type: "number"
7400
- });
7740
+ return TraceGetNumber(fields, entity, tags).value;
7401
7741
  }
7402
7742
  Calculator.GetNumber = GetNumber;
7403
7743
  /**
@@ -7409,15 +7749,61 @@
7409
7749
  * @returns
7410
7750
  */
7411
7751
  function GetString(fields, entity = {}, tags = []) {
7412
- return Calculate({
7413
- fields: fields,
7752
+ return TraceGetString(fields, entity, tags).value;
7753
+ }
7754
+ Calculator.GetString = GetString;
7755
+ /**
7756
+ * Like GetValue, but also returns 'effective' describing how the value was derived.
7757
+ */
7758
+ function TraceGetValue(fields, entity = {}, tags = []) {
7759
+ return TraceCalculate({
7760
+ fields,
7414
7761
  data: entity,
7415
7762
  defaultValue: null,
7416
- tags: tags,
7763
+ tags,
7764
+ type: "any"
7765
+ });
7766
+ }
7767
+ Calculator.TraceGetValue = TraceGetValue;
7768
+ /**
7769
+ * Like GetColor, but also returns 'effective' describing how the color was derived.
7770
+ */
7771
+ function TraceGetColor(fields, entity = {}, tags = []) {
7772
+ return TraceCalculate({
7773
+ fields,
7774
+ data: entity,
7775
+ defaultValue: null,
7776
+ tags,
7777
+ type: "color"
7778
+ });
7779
+ }
7780
+ Calculator.TraceGetColor = TraceGetColor;
7781
+ /**
7782
+ * Like GetNumber, but also returns 'effective' describing how the number was derived.
7783
+ */
7784
+ function TraceGetNumber(fields, entity = {}, tags = []) {
7785
+ return TraceCalculate({
7786
+ fields,
7787
+ data: entity,
7788
+ defaultValue: null,
7789
+ tags,
7790
+ type: "number"
7791
+ });
7792
+ }
7793
+ Calculator.TraceGetNumber = TraceGetNumber;
7794
+ /**
7795
+ * Like GetString, but also returns 'effective' describing how the string was derived.
7796
+ */
7797
+ function TraceGetString(fields, entity = {}, tags = []) {
7798
+ return TraceCalculate({
7799
+ fields,
7800
+ data: entity,
7801
+ defaultValue: null,
7802
+ tags,
7417
7803
  type: "string"
7418
7804
  });
7419
7805
  }
7420
- Calculator.GetString = GetString;
7806
+ Calculator.TraceGetString = TraceGetString;
7421
7807
  /**
7422
7808
  * Calculates a mapping value. This can return any value type.
7423
7809
  * It is intended to be parsed and validated within a value-type context. Eg: GetColor, GetNumber, GetString.
@@ -7426,114 +7812,7 @@
7426
7812
  * @returns
7427
7813
  */
7428
7814
  function GetMappingValue(value, entity) {
7429
- const attrPaths = parseLegacyPath(value.field);
7430
- for (let i = 0; i < attrPaths.length; i++) {
7431
- const attrPath = attrPaths[i];
7432
- let eValue = exports.Entity.GetValue({
7433
- entity: entity,
7434
- path: attrPath
7435
- });
7436
- let isValueNum = !isNaN(+eValue);
7437
- if (eValue == null) {
7438
- isValueNum = false;
7439
- }
7440
- for (let i = 0; i < value.values.length; i++) {
7441
- const option = value.values[i];
7442
- const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
7443
- // Check each field value in the array.
7444
- for (let j = 0; j < fieldValues.length; j++) {
7445
- let mapValue = fieldValues[j];
7446
- // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
7447
- // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
7448
- if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
7449
- try {
7450
- let jsEval = mapValue.replace("JS:", "").trim();
7451
- const attrPathStr = exports.PathUtils.Wrap(attrPath);
7452
- jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
7453
- jsEval = exports.BruceVariable.SwapValues({
7454
- str: jsEval,
7455
- entity: entity
7456
- });
7457
- // https://rollupjs.org/guide/en/#avoiding-eval
7458
- // This stops eval warning.
7459
- const eval2 = eval;
7460
- mapValue = eval2(jsEval);
7461
- // We currently expect eval to return a validity bool.
7462
- // So it either matches and we return it, or it doesn't and we continue.
7463
- if (mapValue) {
7464
- return option.appliedValue;
7465
- }
7466
- else {
7467
- continue;
7468
- }
7469
- }
7470
- catch (exception) {
7471
- const e = exception;
7472
- let suppress = false;
7473
- if (e && typeof e == "object") {
7474
- const msg = e.message;
7475
- suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
7476
- }
7477
- if (!suppress) {
7478
- console.error(e);
7479
- }
7480
- // Eval failed, therefor not a valid mapping-row.
7481
- continue;
7482
- }
7483
- }
7484
- let isMapValueNum = !isNaN(+mapValue);
7485
- if (isMapValueNum == null) {
7486
- isMapValueNum = false;
7487
- }
7488
- if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
7489
- if (+mapValue == +eValue) {
7490
- return option.appliedValue;
7491
- }
7492
- const mapSplit = mapValue.split("-");
7493
- if (mapSplit.length == 2) {
7494
- const min = mapSplit[0];
7495
- const max = mapSplit[1];
7496
- if (min != "") {
7497
- if (+eValue < +min) {
7498
- continue;
7499
- }
7500
- }
7501
- if (max != "") {
7502
- if (+eValue > +max) {
7503
- continue;
7504
- }
7505
- }
7506
- if (min == "" && max == "") {
7507
- continue;
7508
- }
7509
- return option.appliedValue;
7510
- }
7511
- }
7512
- else {
7513
- if (mapValue == eValue) {
7514
- return option.appliedValue;
7515
- }
7516
- // Case where Entity value is a boolean but the mapping value is a string.
7517
- // Common as mapping value is typically a user-entered string.
7518
- else if (typeof eValue === "boolean" && typeof mapValue === "string") {
7519
- const eValueStr = eValue ? "true" : "false";
7520
- if (mapValue.toLowerCase() == eValueStr) {
7521
- return option.appliedValue;
7522
- }
7523
- }
7524
- // Handling possible case where the opposite is true.
7525
- // Have not seen this happen yet, but preparing for any future cases.
7526
- else if (typeof mapValue === "boolean" && typeof eValue === "string") {
7527
- const mapValueStr = mapValue ? "true" : "false";
7528
- if (mapValueStr == eValue.toLowerCase()) {
7529
- return option.appliedValue;
7530
- }
7531
- }
7532
- }
7533
- }
7534
- }
7535
- }
7536
- return null;
7815
+ return _getMappingTrace(value, entity).result;
7537
7816
  }
7538
7817
  Calculator.GetMappingValue = GetMappingValue;
7539
7818
  /**
@@ -7546,47 +7825,7 @@
7546
7825
  * @returns
7547
7826
  */
7548
7827
  function GetGradientValue(value, entity, defaultToMin) {
7549
- const min = +value.points[0].position;
7550
- const max = +value.points[value.points.length - 1].position;
7551
- const attrPaths = parseLegacyPath(value.field);
7552
- for (let i = 0; i < attrPaths.length; i++) {
7553
- const attrPath = attrPaths[i];
7554
- let eValue = exports.Entity.GetValue({
7555
- entity: entity,
7556
- path: attrPath
7557
- });
7558
- if (typeof eValue == "string") {
7559
- eValue = Number(eValue);
7560
- }
7561
- if ((!eValue && eValue != 0) || isNaN(eValue)) {
7562
- continue;
7563
- }
7564
- if (eValue >= max) {
7565
- return exports.Color.ColorFromStr(value.points[value.points.length - 1].color);
7566
- }
7567
- else if (eValue <= min) {
7568
- return exports.Color.ColorFromStr(value.points[0].color);
7569
- }
7570
- for (let i = 0; i < value.points.length - 1; i++) {
7571
- const pointA = value.points[i];
7572
- const pointB = value.points[i + 1];
7573
- if (eValue >= pointA.position && eValue <= pointB.position) {
7574
- if (pointA.position == pointB.position) {
7575
- return exports.Color.ColorFromStr(pointA.color);
7576
- }
7577
- const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
7578
- const colorA = exports.Color.ColorFromStr(pointA.color);
7579
- const colorB = exports.Color.ColorFromStr(pointB.color);
7580
- return {
7581
- red: colorA.red + (colorB.red - colorA.red) * distance,
7582
- green: colorA.green + (colorB.green - colorA.green) * distance,
7583
- blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
7584
- alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
7585
- };
7586
- }
7587
- }
7588
- }
7589
- return exports.Color.ColorFromStr(value.points[0].color);
7828
+ return _getGradientTrace(value, entity, defaultToMin).result;
7590
7829
  }
7591
7830
  Calculator.GetGradientValue = GetGradientValue;
7592
7831
  /**
@@ -18678,7 +18917,7 @@
18678
18917
  })(exports.UrlUtils || (exports.UrlUtils = {}));
18679
18918
 
18680
18919
  // This is updated with the package.json version on build.
18681
- const VERSION = "7.1.53";
18920
+ const VERSION = "7.1.55";
18682
18921
 
18683
18922
  exports.VERSION = VERSION;
18684
18923
  exports.AbstractApi = AbstractApi;