mx-cloud 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/build/interpret.js +34 -16
  2. package/package.json +1 -1
@@ -928,7 +928,7 @@ class Interpreter extends events_1.EventEmitter {
928
928
  const currentDomTree = yield this.generatePageNodeInformation(page, 'body');
929
929
  const changes = [];
930
930
  const isScrapeList = 'listSelector' in schema;
931
- const findMatchingElement = (currentTree, targetInfo) => {
931
+ const findMatchingElement = (field, currentTree, targetInfo) => {
932
932
  if (currentTree.type !== 'ELEMENT_NODE')
933
933
  return { element: null, confidence: 0 };
934
934
  const directMatchScore = () => {
@@ -1056,13 +1056,20 @@ class Interpreter extends events_1.EventEmitter {
1056
1056
  return score;
1057
1057
  };
1058
1058
  const score = directMatchScore();
1059
- if (score >= 0.7) {
1060
- return { element: currentTree, confidence: score };
1059
+ if (field === 'listSelector') {
1060
+ if (score >= 0.85) {
1061
+ return { element: currentTree, confidence: score };
1062
+ }
1063
+ }
1064
+ else {
1065
+ if (score >= 0.7) {
1066
+ return { element: currentTree, confidence: score };
1067
+ }
1061
1068
  }
1062
1069
  let bestMatch = { element: null, confidence: 0 };
1063
1070
  for (const child of currentTree.children) {
1064
1071
  if (child.type === 'ELEMENT_NODE') {
1065
- const childMatch = findMatchingElement(child, targetInfo);
1072
+ const childMatch = findMatchingElement(field, child, targetInfo);
1066
1073
  if (childMatch.confidence > bestMatch.confidence) {
1067
1074
  bestMatch = childMatch;
1068
1075
  }
@@ -1070,7 +1077,7 @@ class Interpreter extends events_1.EventEmitter {
1070
1077
  }
1071
1078
  return bestMatch;
1072
1079
  };
1073
- const findMatchingParentElement = (currentDomTree, parentNodeInfo) => {
1080
+ const findMatchingParentElement = (field, currentDomTree, parentNodeInfo) => {
1074
1081
  if (currentDomTree.type !== 'ELEMENT_NODE') {
1075
1082
  return { element: null, confidence: 0, changes: [] };
1076
1083
  }
@@ -1169,18 +1176,30 @@ class Interpreter extends events_1.EventEmitter {
1169
1176
  return changes;
1170
1177
  };
1171
1178
  const matchScore = matchesParentElement(currentDomTree);
1172
- if (matchScore >= 0.7) {
1173
- const changes = detectAttributeChanges(currentDomTree);
1174
- return {
1175
- element: currentDomTree,
1176
- confidence: matchScore,
1177
- changes
1178
- };
1179
+ if (field === 'listSelector') {
1180
+ if (matchScore >= 0.85) {
1181
+ const changes = detectAttributeChanges(currentDomTree);
1182
+ return {
1183
+ element: currentDomTree,
1184
+ confidence: matchScore,
1185
+ changes
1186
+ };
1187
+ }
1188
+ }
1189
+ else {
1190
+ if (matchScore >= 0.7) {
1191
+ const changes = detectAttributeChanges(currentDomTree);
1192
+ return {
1193
+ element: currentDomTree,
1194
+ confidence: matchScore,
1195
+ changes
1196
+ };
1197
+ }
1179
1198
  }
1180
1199
  let bestMatch = { element: null, confidence: 0, changes: [] };
1181
1200
  for (const child of currentDomTree.children) {
1182
1201
  if (child.type === 'ELEMENT_NODE') {
1183
- const childResult = findMatchingParentElement(child, parentNodeInfo);
1202
+ const childResult = findMatchingParentElement(field, child, parentNodeInfo);
1184
1203
  if (childResult.confidence > bestMatch.confidence) {
1185
1204
  bestMatch = childResult;
1186
1205
  }
@@ -1226,7 +1245,7 @@ class Interpreter extends events_1.EventEmitter {
1226
1245
  });
1227
1246
  }
1228
1247
  };
1229
- const { element: matchedElement, confidence } = findMatchingElement(currentDomTree, elementConfig.nodeInfo);
1248
+ const { element: matchedElement, confidence } = findMatchingElement(field, currentDomTree, elementConfig.nodeInfo);
1230
1249
  if (matchedElement) {
1231
1250
  const actualElement = yield page.evaluateHandle((element) => {
1232
1251
  function findExactElement(elementInfo) {
@@ -1291,7 +1310,7 @@ class Interpreter extends events_1.EventEmitter {
1291
1310
  checkChanges(elementConfig.nodeInfo, matchedElement, actualElement);
1292
1311
  }
1293
1312
  if ('parent' in elementConfig.nodeInfo && elementConfig.nodeInfo.parent) {
1294
- const { element: matchedParentElement, confidence: parentConfidence } = findMatchingParentElement(currentDomTree, elementConfig.nodeInfo.parent);
1313
+ const { element: matchedParentElement, confidence: parentConfidence } = findMatchingParentElement(field, currentDomTree, elementConfig.nodeInfo.parent);
1295
1314
  if (matchedParentElement && parentConfidence >= 0.5) {
1296
1315
  checkChanges(elementConfig.nodeInfo.parent, matchedParentElement, actualElement, true);
1297
1316
  }
@@ -1420,7 +1439,6 @@ class Interpreter extends events_1.EventEmitter {
1420
1439
  modifiedAction.where.selectors[selectorIndex] = bestSelector;
1421
1440
  }
1422
1441
  }
1423
- throw new Error(`Auto-heal successful for field ${fieldName}`);
1424
1442
  }
1425
1443
  catch (error) {
1426
1444
  console.error(`Auto-heal failed for field ${fieldName}:`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mx-cloud",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "mx cloud",
5
5
  "main": "build/index.js",
6
6
  "typings": "build/index.d.ts",