bruce-models 7.0.4 → 7.0.5

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.
@@ -5232,92 +5232,96 @@
5232
5232
  }
5233
5233
  for (let i = 0; i < value.values.length; i++) {
5234
5234
  const option = value.values[i];
5235
- let mapValue = option.fieldValue;
5236
- // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
5237
- // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
5238
- if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
5239
- try {
5240
- let jsEval = mapValue.replace("JS:", "").trim();
5241
- const attrPathStr = exports.PathUtils.Wrap(attrPath);
5242
- jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
5243
- jsEval = exports.BruceVariable.SwapValues({
5244
- str: jsEval,
5245
- entity: entity
5246
- });
5247
- // https://rollupjs.org/guide/en/#avoiding-eval
5248
- // This stops eval warning.
5249
- const eval2 = eval;
5250
- mapValue = eval2(jsEval);
5251
- // We currently expect eval to return a validity bool.
5252
- // So it either matches and we return it, or it doesn't and we continue.
5253
- if (mapValue) {
5254
- return option.appliedValue;
5255
- }
5256
- else {
5257
- continue;
5258
- }
5259
- }
5260
- catch (exception) {
5261
- const e = exception;
5262
- let suppress = false;
5263
- if (e && typeof e == "object") {
5264
- const msg = e.message;
5265
- suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
5266
- }
5267
- if (!suppress) {
5268
- console.error(e);
5269
- }
5270
- // Eval failed, therefor not a valid mapping-row.
5271
- continue;
5272
- }
5273
- }
5274
- let isMapValueNum = !isNaN(+mapValue);
5275
- if (isMapValueNum == null) {
5276
- isMapValueNum = false;
5277
- }
5278
- if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
5279
- if (+mapValue == +eValue) {
5280
- return option.appliedValue;
5281
- }
5282
- const mapSplit = mapValue.split("-");
5283
- if (mapSplit.length == 2) {
5284
- const min = mapSplit[0];
5285
- const max = mapSplit[1];
5286
- if (min != "") {
5287
- if (+eValue < +min) {
5288
- continue;
5235
+ const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
5236
+ // Check each field value in the array.
5237
+ for (let j = 0; j < fieldValues.length; j++) {
5238
+ let mapValue = fieldValues[j];
5239
+ // If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
5240
+ // This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
5241
+ if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
5242
+ try {
5243
+ let jsEval = mapValue.replace("JS:", "").trim();
5244
+ const attrPathStr = exports.PathUtils.Wrap(attrPath);
5245
+ jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
5246
+ jsEval = exports.BruceVariable.SwapValues({
5247
+ str: jsEval,
5248
+ entity: entity
5249
+ });
5250
+ // https://rollupjs.org/guide/en/#avoiding-eval
5251
+ // This stops eval warning.
5252
+ const eval2 = eval;
5253
+ mapValue = eval2(jsEval);
5254
+ // We currently expect eval to return a validity bool.
5255
+ // So it either matches and we return it, or it doesn't and we continue.
5256
+ if (mapValue) {
5257
+ return option.appliedValue;
5289
5258
  }
5290
- }
5291
- if (max != "") {
5292
- if (+eValue > +max) {
5259
+ else {
5293
5260
  continue;
5294
5261
  }
5295
5262
  }
5296
- if (min == "" && max == "") {
5263
+ catch (exception) {
5264
+ const e = exception;
5265
+ let suppress = false;
5266
+ if (e && typeof e == "object") {
5267
+ const msg = e.message;
5268
+ suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
5269
+ }
5270
+ if (!suppress) {
5271
+ console.error(e);
5272
+ }
5273
+ // Eval failed, therefor not a valid mapping-row.
5297
5274
  continue;
5298
5275
  }
5299
- return option.appliedValue;
5300
5276
  }
5301
- }
5302
- else {
5303
- if (mapValue == eValue) {
5304
- return option.appliedValue;
5277
+ let isMapValueNum = !isNaN(+mapValue);
5278
+ if (isMapValueNum == null) {
5279
+ isMapValueNum = false;
5305
5280
  }
5306
- // Case where Entity value is a boolean but the mapping value is a string.
5307
- // Common as mapping value is typically a user-entered string.
5308
- else if (typeof eValue === "boolean" && typeof mapValue === "string") {
5309
- const eValueStr = eValue ? "true" : "false";
5310
- if (mapValue.toLowerCase() == eValueStr) {
5281
+ if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
5282
+ if (+mapValue == +eValue) {
5283
+ return option.appliedValue;
5284
+ }
5285
+ const mapSplit = mapValue.split("-");
5286
+ if (mapSplit.length == 2) {
5287
+ const min = mapSplit[0];
5288
+ const max = mapSplit[1];
5289
+ if (min != "") {
5290
+ if (+eValue < +min) {
5291
+ continue;
5292
+ }
5293
+ }
5294
+ if (max != "") {
5295
+ if (+eValue > +max) {
5296
+ continue;
5297
+ }
5298
+ }
5299
+ if (min == "" && max == "") {
5300
+ continue;
5301
+ }
5311
5302
  return option.appliedValue;
5312
5303
  }
5313
5304
  }
5314
- // Handling possible case where the opposite is true.
5315
- // Have not seen this happen yet, but preparing for any future cases.
5316
- else if (typeof mapValue === "boolean" && typeof eValue === "string") {
5317
- const mapValueStr = mapValue ? "true" : "false";
5318
- if (mapValueStr == eValue.toLowerCase()) {
5305
+ else {
5306
+ if (mapValue == eValue) {
5319
5307
  return option.appliedValue;
5320
5308
  }
5309
+ // Case where Entity value is a boolean but the mapping value is a string.
5310
+ // Common as mapping value is typically a user-entered string.
5311
+ else if (typeof eValue === "boolean" && typeof mapValue === "string") {
5312
+ const eValueStr = eValue ? "true" : "false";
5313
+ if (mapValue.toLowerCase() == eValueStr) {
5314
+ return option.appliedValue;
5315
+ }
5316
+ }
5317
+ // Handling possible case where the opposite is true.
5318
+ // Have not seen this happen yet, but preparing for any future cases.
5319
+ else if (typeof mapValue === "boolean" && typeof eValue === "string") {
5320
+ const mapValueStr = mapValue ? "true" : "false";
5321
+ if (mapValueStr == eValue.toLowerCase()) {
5322
+ return option.appliedValue;
5323
+ }
5324
+ }
5321
5325
  }
5322
5326
  }
5323
5327
  }
@@ -16702,7 +16706,7 @@
16702
16706
  }
16703
16707
 
16704
16708
  // This is updated with the package.json version on build.
16705
- const VERSION = "7.0.4";
16709
+ const VERSION = "7.0.5";
16706
16710
 
16707
16711
  exports.VERSION = VERSION;
16708
16712
  exports.AbstractApi = AbstractApi;