@itentialopensource/adapter-viptela 0.12.1 → 0.12.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.
@@ -3,7 +3,7 @@
3
3
  /* eslint no-param-reassign:warn */
4
4
 
5
5
  const fs = require('fs-extra');
6
- const esprima = require('esprima');
6
+ const acorn = require('acorn');
7
7
 
8
8
  // Getting the base directory:
9
9
  let adaptdir = __dirname;
@@ -44,18 +44,38 @@ function getPathFromEntity(entity, funcName) {
44
44
  const actionJSON = require(entityPath);
45
45
  actionJSON.actions.forEach((action) => {
46
46
  if (action.name === funcName) {
47
- epath = action.entitypath;
47
+ if (typeof action.entitypath === 'object') {
48
+ epath = '';
49
+ const keys = Object.keys(action.entitypath);
50
+ for (let k = 0; k < keys.length; k += 1) {
51
+ epath += `${keys[k]}:${action.entitypath[keys[k]]} <br /> `;
52
+ }
53
+ epath = epath.substring(0, epath.length - 8);
54
+ } else {
55
+ epath = action.entitypath;
56
+ }
48
57
  }
49
58
  });
50
59
  }
51
60
  return epath;
52
61
  }
53
62
 
63
+ function recurseCallExpressions(statement, callList) {
64
+ // Recursively finds all CallExpressions in the syntax tree
65
+ if (statement.type === 'CallExpression') callList.push(statement);
66
+ const keys = Object.keys(statement);
67
+ for (let k = 0; k < keys.length; k += 1) {
68
+ if (typeof statement[keys[k]] === 'object' && statement[keys[k]] !== null) {
69
+ recurseCallExpressions(statement[keys[k]], callList);
70
+ }
71
+ }
72
+ }
73
+
54
74
  function readFileUsingLib(filename, descriptionObj, workflowObj, functionList) {
55
75
  // read the file
56
76
  const aFile = fs.readFileSync(filename, 'utf8');
57
77
  // parsing the file to get the function and class declarations.
58
- const aFileFuncArgs = esprima.parseScript(aFile);
78
+ const aFileFuncArgs = acorn.parse(aFile, { ecmaVersion: 2020 });
59
79
 
60
80
  // Looping through all the declarations parsed:
61
81
  aFileFuncArgs.body.forEach((e) => {
@@ -76,25 +96,40 @@ function readFileUsingLib(filename, descriptionObj, workflowObj, functionList) {
76
96
  });
77
97
 
78
98
  // Getting the entity for the method:
79
- let entity;
80
- method.value.body.body.forEach((statementType) => {
81
- if (statementType.type === 'TryStatement') {
82
- entity = statementType.block.body[0].argument.arguments[0].value;
83
- }
99
+ const callList = [];
100
+ method.value.body.body.forEach((statement) => {
101
+ recurseCallExpressions(statement, callList);
84
102
  });
85
- const entityPath = getPathFromEntity(entity, funcName);
86
-
87
- // Creating and storing the object for the method.
88
- if (entityPath !== undefined) {
89
- functionList.push(
90
- createObjectForFunction(
91
- funcName,
92
- funcArgs,
93
- entityPath,
94
- descriptionObj[funcName],
95
- workflowObj[funcName]
96
- )
97
- );
103
+ const requests = [];
104
+ for (let i = 0; i < callList.length; i += 1) {
105
+ if (callList[i].callee.property && callList[i].callee.property.name === 'identifyRequest') {
106
+ requests.push(callList[i]);
107
+ }
108
+ }
109
+ if (requests.length > 0) {
110
+ const expr = requests[0];
111
+ if (expr.arguments.length < 2) {
112
+ throw new Error(`Bad inputs in method ${funcName}`);
113
+ }
114
+ const entity = expr.arguments[0].value;
115
+ const actionName = expr.arguments[1].value;
116
+ if (expr !== undefined && (expr.arguments[0].type !== 'Literal' || expr.arguments[1].type !== 'Literal')) {
117
+ throw new Error(`Bad inputs in method ${funcName}`);
118
+ }
119
+ const entityPath = getPathFromEntity(entity, actionName);
120
+
121
+ // Creating and storing the object for the method.
122
+ if (entityPath !== undefined) {
123
+ functionList.push(
124
+ createObjectForFunction(
125
+ funcName,
126
+ funcArgs,
127
+ entityPath,
128
+ descriptionObj[funcName],
129
+ workflowObj[funcName]
130
+ )
131
+ );
132
+ }
98
133
  }
99
134
  });
100
135
  }
@@ -109,7 +144,7 @@ function readJSONFile(filename, descriptionObj, workflowObj) {
109
144
  methodArray.forEach((methodName) => {
110
145
  // Getting the method description and workflow:
111
146
  const funcName = methodName.name;
112
- descriptionObj[funcName] = methodName.description;
147
+ descriptionObj[funcName] = methodName.summary ? methodName.summary : methodName.description;
113
148
  workflowObj[funcName] = methodName.task ? 'Yes' : 'No';
114
149
  });
115
150
  }