@aws-amplify/predictions 4.0.21 → 4.0.22-unstable.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.
@@ -91805,6 +91805,7 @@ const props = [
91805
91805
  'supressEmptyNode',
91806
91806
  'tagValueProcessor',
91807
91807
  'attrValueProcessor',
91808
+ 'rootNodeName', //when array as root
91808
91809
  ];
91809
91810
 
91810
91811
  function Parser(options) {
@@ -91852,6 +91853,11 @@ function Parser(options) {
91852
91853
  }
91853
91854
 
91854
91855
  Parser.prototype.parse = function(jObj) {
91856
+ if(Array.isArray(jObj) && this.options.rootNodeName && this.options.rootNodeName.length > 1){
91857
+ jObj = {
91858
+ [this.options.rootNodeName] : jObj
91859
+ }
91860
+ }
91855
91861
  return this.j2x(jObj, 0).val;
91856
91862
  };
91857
91863
 
@@ -92101,7 +92107,7 @@ const _e = function(node, e_schema, options) {
92101
92107
  //attributes can't be repeated. hence check in children tags only
92102
92108
  str += chars.arrStart;
92103
92109
  const itemSchema = e_schema[0];
92104
- //var itemSchemaType = itemSchema;
92110
+ //const itemSchemaType = itemSchema;
92105
92111
  const arr_len = node.length;
92106
92112
 
92107
92113
  if (typeof itemSchema === 'string') {
@@ -92215,7 +92221,7 @@ const convertToJson = function(node, options, parentTagName) {
92215
92221
  const jObj = {};
92216
92222
 
92217
92223
  // when no child node or attr is present
92218
- if ((!node.child || util.isEmptyObject(node.child)) && (!node.attrsMap || util.isEmptyObject(node.attrsMap))) {
92224
+ if (!options.alwaysCreateTextNode && (!node.child || util.isEmptyObject(node.child)) && (!node.attrsMap || util.isEmptyObject(node.attrsMap))) {
92219
92225
  return util.isExist(node.val) ? node.val : '';
92220
92226
  }
92221
92227
 
@@ -92282,10 +92288,10 @@ const _cToJsonStr = function(node, options, level) {
92282
92288
  const keys = Object.keys(node.child);
92283
92289
 
92284
92290
  for (let index = 0; index < keys.length; index++) {
92285
- var tagname = keys[index];
92291
+ const tagname = keys[index];
92286
92292
  if (node.child[tagname] && node.child[tagname].length > 1) {
92287
92293
  jObj += '"' + tagname + '" : [ ';
92288
- for (var tag in node.child[tagname]) {
92294
+ for (let tag in node.child[tagname]) {
92289
92295
  jObj += _cToJsonStr(node.child[tagname][tag], options) + ' , ';
92290
92296
  }
92291
92297
  jObj = jObj.substr(0, jObj.length - 1) + ' ] '; //remove extra comma in last
@@ -92436,6 +92442,7 @@ const getAllMatches = function(string, regex) {
92436
92442
  let match = regex.exec(string);
92437
92443
  while (match) {
92438
92444
  const allmatches = [];
92445
+ allmatches.startIndex = regex.lastIndex - match[0].length;
92439
92446
  const len = match.length;
92440
92447
  for (let index = 0; index < len; index++) {
92441
92448
  allmatches.push(match[index]);
@@ -92493,7 +92500,7 @@ exports.getValue = function(v) {
92493
92500
  // const fakeCallNoReturn = function() {};
92494
92501
 
92495
92502
  exports.buildOptions = function(options, defaultOptions, props) {
92496
- var newOptions = {};
92503
+ let newOptions = {};
92497
92504
  if (!options) {
92498
92505
  return defaultOptions; //if there are not options
92499
92506
  }
@@ -92580,7 +92587,7 @@ exports.validate = function (xmlData, options) {
92580
92587
  }else if (xmlData[i] === '<') {
92581
92588
  //starting of tag
92582
92589
  //read until you reach to '>' avoiding any '>' in attribute value
92583
-
92590
+ let tagStartPos = i;
92584
92591
  i++;
92585
92592
 
92586
92593
  if (xmlData[i] === '!') {
@@ -92616,7 +92623,7 @@ exports.validate = function (xmlData, options) {
92616
92623
  if (!validateTagName(tagName)) {
92617
92624
  let msg;
92618
92625
  if (tagName.trim().length === 0) {
92619
- msg = "There is an unnecessary space between tag name and backward slash '</ ..'.";
92626
+ msg = "Invalid space after '<'.";
92620
92627
  } else {
92621
92628
  msg = "Tag '"+tagName+"' is an invalid name.";
92622
92629
  }
@@ -92632,6 +92639,7 @@ exports.validate = function (xmlData, options) {
92632
92639
 
92633
92640
  if (attrStr[attrStr.length - 1] === '/') {
92634
92641
  //self closing tag
92642
+ const attrStrStart = i - attrStr.length;
92635
92643
  attrStr = attrStr.substring(0, attrStr.length - 1);
92636
92644
  const isValid = validateAttributeString(attrStr, options);
92637
92645
  if (isValid === true) {
@@ -92641,17 +92649,20 @@ exports.validate = function (xmlData, options) {
92641
92649
  //the result from the nested function returns the position of the error within the attribute
92642
92650
  //in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
92643
92651
  //this gives us the absolute index in the entire xml, which we can use to find the line at last
92644
- return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
92652
+ return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
92645
92653
  }
92646
92654
  } else if (closingTag) {
92647
92655
  if (!result.tagClosed) {
92648
92656
  return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
92649
92657
  } else if (attrStr.trim().length > 0) {
92650
- return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, i));
92658
+ return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
92651
92659
  } else {
92652
92660
  const otg = tags.pop();
92653
- if (tagName !== otg) {
92654
- return getErrorObject('InvalidTag', "Closing tag '"+otg+"' is expected inplace of '"+tagName+"'.", getLineNumberForPosition(xmlData, i));
92661
+ if (tagName !== otg.tagName) {
92662
+ let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
92663
+ return getErrorObject('InvalidTag',
92664
+ "Expected closing tag '"+otg.tagName+"' (opened in line "+openPos.line+", col "+openPos.col+") instead of closing tag '"+tagName+"'.",
92665
+ getLineNumberForPosition(xmlData, tagStartPos));
92655
92666
  }
92656
92667
 
92657
92668
  //when there are no more tags, we reached the root level.
@@ -92672,7 +92683,7 @@ exports.validate = function (xmlData, options) {
92672
92683
  if (reachedRoot === true) {
92673
92684
  return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
92674
92685
  } else {
92675
- tags.push(tagName);
92686
+ tags.push({tagName, tagStartPos});
92676
92687
  }
92677
92688
  tagFound = true;
92678
92689
  }
@@ -92713,8 +92724,12 @@ exports.validate = function (xmlData, options) {
92713
92724
 
92714
92725
  if (!tagFound) {
92715
92726
  return getErrorObject('InvalidXml', 'Start tag expected.', 1);
92716
- } else if (tags.length > 0) {
92717
- return getErrorObject('InvalidXml', "Invalid '"+JSON.stringify(tags, null, 4).replace(/\r?\n/g, '')+"' found.", 1);
92727
+ }else if (tags.length == 1) {
92728
+ return getErrorObject('InvalidTag', "Unclosed tag '"+tags[0].tagName+"'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
92729
+ }else if (tags.length > 0) {
92730
+ return getErrorObject('InvalidXml', "Invalid '"+
92731
+ JSON.stringify(tags.map(t => t.tagName), null, 4).replace(/\r?\n/g, '')+
92732
+ "' found.", {line: 1, col: 1});
92718
92733
  }
92719
92734
 
92720
92735
  return true;
@@ -92726,11 +92741,11 @@ exports.validate = function (xmlData, options) {
92726
92741
  * @param {*} i
92727
92742
  */
92728
92743
  function readPI(xmlData, i) {
92729
- var start = i;
92744
+ const start = i;
92730
92745
  for (; i < xmlData.length; i++) {
92731
92746
  if (xmlData[i] == '?' || xmlData[i] == ' ') {
92732
92747
  //tagname
92733
- var tagname = xmlData.substr(start, i - start);
92748
+ const tagname = xmlData.substr(start, i - start);
92734
92749
  if (i > 5 && tagname === 'xml') {
92735
92750
  return getErrorObject('InvalidXml', 'XML declaration allowed only at the start of the document.', getLineNumberForPosition(xmlData, i));
92736
92751
  } else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
@@ -92796,8 +92811,8 @@ function readCommentAndCDATA(xmlData, i) {
92796
92811
  return i;
92797
92812
  }
92798
92813
 
92799
- var doubleQuote = '"';
92800
- var singleQuote = "'";
92814
+ const doubleQuote = '"';
92815
+ const singleQuote = "'";
92801
92816
 
92802
92817
  /**
92803
92818
  * Keep reading xmlData until '<' is found outside the attribute value.
@@ -92814,7 +92829,6 @@ function readAttributeStr(xmlData, i) {
92814
92829
  startChar = xmlData[i];
92815
92830
  } else if (startChar !== xmlData[i]) {
92816
92831
  //if vaue is enclosed with double quote then single quotes are allowed inside the value and vice versa
92817
- continue;
92818
92832
  } else {
92819
92833
  startChar = '';
92820
92834
  }
@@ -92855,23 +92869,23 @@ function validateAttributeString(attrStr, options) {
92855
92869
  for (let i = 0; i < matches.length; i++) {
92856
92870
  if (matches[i][1].length === 0) {
92857
92871
  //nospace before attribute name: a="sd"b="saf"
92858
- return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' has no space in starting.", getPositionFromMatch(attrStr, matches[i][0]))
92872
+ return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' has no space in starting.", getPositionFromMatch(matches[i]))
92859
92873
  } else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
92860
92874
  //independent attribute: ab
92861
- return getErrorObject('InvalidAttr', "boolean attribute '"+matches[i][2]+"' is not allowed.", getPositionFromMatch(attrStr, matches[i][0]));
92875
+ return getErrorObject('InvalidAttr', "boolean attribute '"+matches[i][2]+"' is not allowed.", getPositionFromMatch(matches[i]));
92862
92876
  }
92863
92877
  /* else if(matches[i][6] === undefined){//attribute without value: ab=
92864
92878
  return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
92865
92879
  } */
92866
92880
  const attrName = matches[i][2];
92867
92881
  if (!validateAttrName(attrName)) {
92868
- return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is an invalid name.", getPositionFromMatch(attrStr, matches[i][0]));
92882
+ return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is an invalid name.", getPositionFromMatch(matches[i]));
92869
92883
  }
92870
92884
  if (!attrNames.hasOwnProperty(attrName)) {
92871
92885
  //check for duplicate attribute.
92872
92886
  attrNames[attrName] = 1;
92873
92887
  } else {
92874
- return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is repeated.", getPositionFromMatch(attrStr, matches[i][0]));
92888
+ return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is repeated.", getPositionFromMatch(matches[i]));
92875
92889
  }
92876
92890
  }
92877
92891
 
@@ -92918,7 +92932,8 @@ function getErrorObject(code, message, lineNumber) {
92918
92932
  err: {
92919
92933
  code: code,
92920
92934
  msg: message,
92921
- line: lineNumber,
92935
+ line: lineNumber.line || lineNumber,
92936
+ col: lineNumber.col,
92922
92937
  },
92923
92938
  };
92924
92939
  }
@@ -92935,13 +92950,18 @@ function validateTagName(tagname) {
92935
92950
 
92936
92951
  //this function returns the line number for the character at the given index
92937
92952
  function getLineNumberForPosition(xmlData, index) {
92938
- var lines = xmlData.substring(0, index).split(/\r?\n/);
92939
- return lines.length;
92953
+ const lines = xmlData.substring(0, index).split(/\r?\n/);
92954
+ return {
92955
+ line: lines.length,
92956
+
92957
+ // column number is last line's length + 1, because column numbering starts at 1:
92958
+ col: lines[lines.length - 1].length + 1
92959
+ };
92940
92960
  }
92941
92961
 
92942
- //this function returns the position of the last character of match within attrStr
92943
- function getPositionFromMatch(attrStr, match) {
92944
- return attrStr.indexOf(match) + match.length;
92962
+ //this function returns the position of the first character of match within attrStr
92963
+ function getPositionFromMatch(match) {
92964
+ return match.startIndex + match[1].length;
92945
92965
  }
92946
92966
 
92947
92967
 
@@ -93030,7 +93050,8 @@ const defaultOptions = {
93030
93050
  attrValueProcessor: function(a, attrName) {
93031
93051
  return a;
93032
93052
  },
93033
- stopNodes: []
93053
+ stopNodes: [],
93054
+ alwaysCreateTextNode: false
93034
93055
  //decodeStrict: false,
93035
93056
  };
93036
93057
 
@@ -93053,7 +93074,8 @@ const props = [
93053
93074
  'attrValueProcessor',
93054
93075
  'parseTrueNumberOnly',
93055
93076
  'numParseOptions',
93056
- 'stopNodes'
93077
+ 'stopNodes',
93078
+ 'alwaysCreateTextNode'
93057
93079
  ];
93058
93080
  exports.props = props;
93059
93081