@itentialopensource/adapter-oracle_cloud 0.1.1 → 0.3.0
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.
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +859 -0
- package/CHANGELOG.md +17 -2
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +3 -148
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +235 -576
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +371 -270
- package/adapterBase.js +843 -419
- package/changelogs/changelog.md +16 -0
- package/entities/.generic/action.json +105 -0
- package/entities/.generic/schema.json +6 -1
- package/error.json +6 -0
- package/metadata.json +49 -0
- package/package.json +24 -24
- package/pronghorn.json +680 -100
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +830 -9
- package/refs?service=git-upload-pack +0 -0
- package/report/adapter-openapi.json +11867 -0
- package/report/adapter-openapi.yaml +11966 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1653049581192.json +120 -0
- package/report/updateReport1691507422430.json +120 -0
- package/report/updateReport1692202455354.json +120 -0
- package/report/updateReport1694460824360.json +120 -0
- package/report/updateReport1698420559437.json +120 -0
- package/sampleProperties.json +153 -3
- package/test/integration/adapterTestBasicGet.js +3 -5
- package/test/integration/adapterTestConnectivity.js +91 -42
- package/test/integration/adapterTestIntegration.js +176 -127
- package/test/unit/adapterBaseTestUnit.js +388 -308
- package/test/unit/adapterTestUnit.js +643 -402
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +1 -1
- package/utils/artifactize.js +1 -1
- package/utils/checkMigrate.js +1 -1
- package/utils/entitiesToDB.js +12 -57
- package/utils/findPath.js +1 -1
- package/utils/methodDocumentor.js +273 -0
- package/utils/modify.js +13 -15
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +5 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +123 -53
- package/utils/tbUtils.js +92 -48
- package/utils/testRunner.js +17 -17
- package/utils/troubleshootingAdapter.js +9 -6
- package/workflows/README.md +0 -3
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
/* eslint global-require:warn */
|
|
4
|
+
/* eslint import/no-dynamic-require:warn */
|
|
5
|
+
/* eslint prefer-destructuring:warn */
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs-extra');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This script will determine the information about the adapter and store
|
|
12
|
+
* it into a file in the adapter.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* get adapter information
|
|
17
|
+
*/
|
|
18
|
+
function adapterInfo() {
|
|
19
|
+
// set the base pase of the adapter - tool shoud be one level up in utils
|
|
20
|
+
let adaptdir = __dirname;
|
|
21
|
+
const infoRes = {};
|
|
22
|
+
|
|
23
|
+
if (adaptdir.endsWith('/utils')) {
|
|
24
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 6);
|
|
25
|
+
}
|
|
26
|
+
const pack = require(`${adaptdir}/package.json`);
|
|
27
|
+
infoRes.version = pack.version;
|
|
28
|
+
|
|
29
|
+
let configCount = 0;
|
|
30
|
+
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
31
|
+
const cFile = fs.readFileSync(`${adaptdir}/pronghorn.json`, 'utf8');
|
|
32
|
+
configCount += cFile.split('\n').length;
|
|
33
|
+
} else {
|
|
34
|
+
console.log('Missing - pronghorn.json');
|
|
35
|
+
}
|
|
36
|
+
if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
|
|
37
|
+
const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
|
|
38
|
+
configCount += cFile.split('\n').length;
|
|
39
|
+
} else {
|
|
40
|
+
console.log('Missing - propertiesSchema.json');
|
|
41
|
+
}
|
|
42
|
+
if (fs.existsSync(`${adaptdir}/error.json`)) {
|
|
43
|
+
const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
|
|
44
|
+
configCount += cFile.split('\n').length;
|
|
45
|
+
} else {
|
|
46
|
+
console.log('Missing - error.json');
|
|
47
|
+
}
|
|
48
|
+
const entitydir = path.join(adaptdir, '/entities');
|
|
49
|
+
if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
|
|
50
|
+
const entities = fs.readdirSync(entitydir);
|
|
51
|
+
// need to go through each entity in the entities directory
|
|
52
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
53
|
+
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
54
|
+
const cfiles = fs.readdirSync(entitydir);
|
|
55
|
+
for (let c = 0; c < cfiles.length; c += 1) {
|
|
56
|
+
if (cfiles[c].endsWith('.json')) {
|
|
57
|
+
const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
|
|
58
|
+
configCount += ccFile.split('\n').length;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
console.log('Could not find the entities directory');
|
|
65
|
+
}
|
|
66
|
+
infoRes.configLines = configCount;
|
|
67
|
+
|
|
68
|
+
let scodeCount = 0;
|
|
69
|
+
if (fs.existsSync(`${adaptdir}/utils/artifactize.js`)) {
|
|
70
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/artifactize.js`, 'utf8');
|
|
71
|
+
scodeCount += sFile.split('\n').length;
|
|
72
|
+
} else {
|
|
73
|
+
console.log('Missing - utils/artifactize.js');
|
|
74
|
+
}
|
|
75
|
+
if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
|
|
76
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
|
|
77
|
+
scodeCount += sFile.split('\n').length;
|
|
78
|
+
} else {
|
|
79
|
+
console.log('Missing - utils/basicGet.js');
|
|
80
|
+
}
|
|
81
|
+
if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
|
|
82
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
|
|
83
|
+
scodeCount += sFile.split('\n').length;
|
|
84
|
+
} else {
|
|
85
|
+
console.log('Missing - utils/checkMigrate.js');
|
|
86
|
+
}
|
|
87
|
+
if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
|
|
88
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
|
|
89
|
+
scodeCount += sFile.split('\n').length;
|
|
90
|
+
} else {
|
|
91
|
+
console.log('Missing - utils/findPath.js');
|
|
92
|
+
}
|
|
93
|
+
if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
|
|
94
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
|
|
95
|
+
scodeCount += sFile.split('\n').length;
|
|
96
|
+
} else {
|
|
97
|
+
console.log('Missing - utils/modify.js');
|
|
98
|
+
}
|
|
99
|
+
if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
|
|
100
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
|
|
101
|
+
scodeCount += sFile.split('\n').length;
|
|
102
|
+
} else {
|
|
103
|
+
console.log('Missing - utils/packModificationScript.js');
|
|
104
|
+
}
|
|
105
|
+
if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
|
|
106
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
|
|
107
|
+
scodeCount += sFile.split('\n').length;
|
|
108
|
+
} else {
|
|
109
|
+
console.log('Missing - utils/setup.js');
|
|
110
|
+
}
|
|
111
|
+
if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
|
|
112
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
|
|
113
|
+
scodeCount += sFile.split('\n').length;
|
|
114
|
+
} else {
|
|
115
|
+
console.log('Missing - utils/tbScript.js');
|
|
116
|
+
}
|
|
117
|
+
if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
|
|
118
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
|
|
119
|
+
scodeCount += sFile.split('\n').length;
|
|
120
|
+
} else {
|
|
121
|
+
console.log('Missing - utils/tbUtils.js');
|
|
122
|
+
}
|
|
123
|
+
if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
|
|
124
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
|
|
125
|
+
scodeCount += sFile.split('\n').length;
|
|
126
|
+
} else {
|
|
127
|
+
console.log('Missing - utils/testRunner.js');
|
|
128
|
+
}
|
|
129
|
+
if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
|
|
130
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
|
|
131
|
+
scodeCount += sFile.split('\n').length;
|
|
132
|
+
} else {
|
|
133
|
+
console.log('Missing - utils/troubleshootingAdapter.js');
|
|
134
|
+
}
|
|
135
|
+
infoRes.scriptLines = scodeCount;
|
|
136
|
+
|
|
137
|
+
let codeCount = 0;
|
|
138
|
+
if (fs.existsSync(`${adaptdir}/adapter.js`)) {
|
|
139
|
+
const aFile = fs.readFileSync(`${adaptdir}/adapter.js`, 'utf8');
|
|
140
|
+
codeCount += aFile.split('\n').length;
|
|
141
|
+
} else {
|
|
142
|
+
console.log('Missing - utils/adapter.js');
|
|
143
|
+
}
|
|
144
|
+
if (fs.existsSync(`${adaptdir}/adapterBase.js`)) {
|
|
145
|
+
const aFile = fs.readFileSync(`${adaptdir}/adapterBase.js`, 'utf8');
|
|
146
|
+
codeCount += aFile.split('\n').length;
|
|
147
|
+
} else {
|
|
148
|
+
console.log('Missing - utils/adapterBase.js');
|
|
149
|
+
}
|
|
150
|
+
infoRes.codeLines = codeCount;
|
|
151
|
+
|
|
152
|
+
let tcodeCount = 0;
|
|
153
|
+
let ttestCount = 0;
|
|
154
|
+
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
|
|
155
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
|
|
156
|
+
tcodeCount += tFile.split('\n').length;
|
|
157
|
+
ttestCount += tFile.split('it(\'').length;
|
|
158
|
+
} else {
|
|
159
|
+
console.log('Missing - test/integration/adapterTestBasicGet.js');
|
|
160
|
+
}
|
|
161
|
+
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
|
|
162
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
|
|
163
|
+
tcodeCount += tFile.split('\n').length;
|
|
164
|
+
ttestCount += tFile.split('it(\'').length;
|
|
165
|
+
} else {
|
|
166
|
+
console.log('Missing - test/integration/adapterTestConnectivity.js');
|
|
167
|
+
}
|
|
168
|
+
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
|
|
169
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
|
|
170
|
+
tcodeCount += tFile.split('\n').length;
|
|
171
|
+
ttestCount += tFile.split('it(\'').length;
|
|
172
|
+
} else {
|
|
173
|
+
console.log('Missing - test/integration/adapterTestIntegration.js');
|
|
174
|
+
}
|
|
175
|
+
if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
|
|
176
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
|
|
177
|
+
tcodeCount += tFile.split('\n').length;
|
|
178
|
+
ttestCount += tFile.split('it(\'').length;
|
|
179
|
+
} else {
|
|
180
|
+
console.log('Missing - test/unit/adapterBaseTestUnit.js');
|
|
181
|
+
}
|
|
182
|
+
if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
|
|
183
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
|
|
184
|
+
tcodeCount += tFile.split('\n').length;
|
|
185
|
+
ttestCount += tFile.split('it(\'').length;
|
|
186
|
+
} else {
|
|
187
|
+
console.log('Missing - test/unit/adapterTestUnit.js');
|
|
188
|
+
}
|
|
189
|
+
infoRes.testLines = tcodeCount;
|
|
190
|
+
infoRes.testCases = ttestCount;
|
|
191
|
+
infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
|
|
192
|
+
|
|
193
|
+
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
194
|
+
// Read the entity schema from the file system
|
|
195
|
+
const phFile = path.join(adaptdir, '/pronghorn.json');
|
|
196
|
+
const prong = require(phFile);
|
|
197
|
+
infoRes.wfTasks = prong.methods.length;
|
|
198
|
+
} else {
|
|
199
|
+
console.log('Missing - pronghorn.json');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
console.log(JSON.stringify(infoRes));
|
|
203
|
+
fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
adapterInfo();
|
package/utils/addAuth.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/* eslint global-require: warn */
|
|
3
3
|
/* eslint import/no-dynamic-require: warn */
|
|
4
4
|
|
|
5
|
-
const rls = require('readline-sync');
|
|
6
5
|
const path = require('path');
|
|
7
6
|
const fs = require('fs');
|
|
7
|
+
const rls = require('readline-sync');
|
|
8
8
|
|
|
9
9
|
function getQuestions(props, obj) {
|
|
10
10
|
const questions = props.map((p) => `${p}: ${(obj[p] !== undefined) ? `(${obj[p]})` : ''} `);
|
package/utils/artifactize.js
CHANGED
package/utils/checkMigrate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { execSync } = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
2
3
|
const semver = require('semver');
|
|
3
4
|
const axios = require('axios');
|
|
4
|
-
const fs = require('fs');
|
|
5
5
|
const packageJson = require('../package.json');
|
|
6
6
|
|
|
7
7
|
const localEngineVer = packageJson.engineVersion;
|
package/utils/entitiesToDB.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
/* eslint global-require: warn */
|
|
8
8
|
/* eslint no-unused-vars: warn */
|
|
9
9
|
/* eslint import/no-unresolved: warn */
|
|
10
|
+
/* eslint no-promise-executor-return: warn */
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* This script is used to read through an adapter's entities files
|
|
@@ -14,10 +15,8 @@
|
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
const fs = require('fs');
|
|
17
|
-
const { MongoClient } = require('mongodb');
|
|
18
18
|
const path = require('path');
|
|
19
|
-
|
|
20
|
-
// const { string } = require('yargs');
|
|
19
|
+
const utils = require('./tbUtils');
|
|
21
20
|
|
|
22
21
|
// get the pronghorn database information
|
|
23
22
|
const getPronghornProps = async (iapDir) => {
|
|
@@ -99,7 +98,7 @@ const optionsHandler = (options) => {
|
|
|
99
98
|
/**
|
|
100
99
|
* Function used to put the adapter configuration into the provided database
|
|
101
100
|
*/
|
|
102
|
-
const moveEntitiesToDB = (targetPath, options) => {
|
|
101
|
+
const moveEntitiesToDB = async (targetPath, options) => {
|
|
103
102
|
// set local variables
|
|
104
103
|
let myOpts = options;
|
|
105
104
|
let myPath = targetPath;
|
|
@@ -120,25 +119,7 @@ const moveEntitiesToDB = (targetPath, options) => {
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
// get the pronghorn database properties
|
|
123
|
-
optionsHandler(options).then((currentProps) => {
|
|
124
|
-
let mongoUrl;
|
|
125
|
-
let dbName;
|
|
126
|
-
|
|
127
|
-
// find the mongo properties so we can connect
|
|
128
|
-
if (currentProps.mongoProps) {
|
|
129
|
-
mongoUrl = currentProps.mongoProps.url;
|
|
130
|
-
dbName = currentProps.mongoProps.db;
|
|
131
|
-
} else if (currentProps.mongo) {
|
|
132
|
-
if (currentProps.mongo.url) {
|
|
133
|
-
mongoUrl = currentProps.mongo.url;
|
|
134
|
-
} else {
|
|
135
|
-
mongoUrl = `mongodb://${currentProps.mongo.host}:${currentProps.mongo.port}`;
|
|
136
|
-
}
|
|
137
|
-
dbName = currentProps.mongo.database;
|
|
138
|
-
} else {
|
|
139
|
-
throw new Error('Mongo properties are not specified in adapter preferences!');
|
|
140
|
-
}
|
|
141
|
-
|
|
122
|
+
return optionsHandler(options).then(async (currentProps) => {
|
|
142
123
|
// Check valid filepath provided
|
|
143
124
|
if (!myPath) {
|
|
144
125
|
// if no path use the current directory without the utils
|
|
@@ -184,41 +165,15 @@ const moveEntitiesToDB = (targetPath, options) => {
|
|
|
184
165
|
});
|
|
185
166
|
|
|
186
167
|
// Upload documents to db collection
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// insert the documents into the collection
|
|
196
|
-
collection.insertMany(docs, { checkKeys: false }, (error, res) => {
|
|
197
|
-
if (error) {
|
|
198
|
-
log.error(JSON.stringify(error));
|
|
199
|
-
throw error;
|
|
200
|
-
}
|
|
201
|
-
// log the insertion, close the database and return
|
|
202
|
-
log.debug(`Inserted ${docs.length} documents to ${dbName}.${myOpts.targetCollection} with response ${JSON.stringify(res)}`);
|
|
203
|
-
db.close();
|
|
204
|
-
return res;
|
|
205
|
-
});
|
|
206
|
-
});
|
|
168
|
+
const db = await utils.connect(currentProps).catch((err) => { console.error(err); throw err; });
|
|
169
|
+
if (!db) {
|
|
170
|
+
console.error('Error occured when connectiong to database', currentProps);
|
|
171
|
+
throw new Error('Database not found');
|
|
172
|
+
}
|
|
173
|
+
const collection = db.collection(myOpts.targetCollection);
|
|
174
|
+
const res = await collection.insertMany(docs, { checkKeys: false }).catch((err) => { console.error(err); throw err; });
|
|
175
|
+
return res;
|
|
207
176
|
});
|
|
208
177
|
};
|
|
209
178
|
|
|
210
|
-
// const args = process.argv.slice(2);
|
|
211
|
-
|
|
212
|
-
// throw new SyntaxError(args[0]);
|
|
213
|
-
|
|
214
|
-
// if (args.length === 0) {
|
|
215
|
-
// console.error('ERROR: target path not specified!');
|
|
216
|
-
// } else if (args[0] === 'help') {
|
|
217
|
-
// log.trace('node ./entitiesToDB <target path> <options object: {iapDir: string, pronghornProps: string, targetCollection: string}>');
|
|
218
|
-
// } else if (args.length === 1) {
|
|
219
|
-
// console.error('ERROR: IAP directory not specified');
|
|
220
|
-
// } else {
|
|
221
|
-
// moveEntitiesToDB(args[0], args[1]);
|
|
222
|
-
// }
|
|
223
|
-
|
|
224
179
|
module.exports = { moveEntitiesToDB };
|
package/utils/findPath.js
CHANGED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/* eslint global-require:warn */
|
|
2
|
+
/* eslint import/no-dynamic-require:warn */
|
|
3
|
+
/* eslint no-param-reassign:warn */
|
|
4
|
+
|
|
5
|
+
const fs = require('fs-extra');
|
|
6
|
+
const acorn = require('acorn');
|
|
7
|
+
|
|
8
|
+
// Getting the base directory:
|
|
9
|
+
let adaptdir = __dirname;
|
|
10
|
+
if (adaptdir.endsWith('/utils')) {
|
|
11
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 6);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function createObjectForFunction(
|
|
15
|
+
funcName,
|
|
16
|
+
funcArgs,
|
|
17
|
+
entityPath,
|
|
18
|
+
description,
|
|
19
|
+
workflow
|
|
20
|
+
) {
|
|
21
|
+
const funcObject = {};
|
|
22
|
+
// if the entity path is not set, then the object is not created.
|
|
23
|
+
if (entityPath !== undefined) {
|
|
24
|
+
funcObject.method_signature = `${funcName}(${funcArgs.join(', ')})`;
|
|
25
|
+
funcObject.path = entityPath;
|
|
26
|
+
if (description === undefined) {
|
|
27
|
+
funcObject.description = '';
|
|
28
|
+
funcObject.workflow = 'No';
|
|
29
|
+
} else {
|
|
30
|
+
funcObject.description = description;
|
|
31
|
+
funcObject.workflow = workflow;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return funcObject;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getPathFromEntity(entity, funcName) {
|
|
38
|
+
let epath;
|
|
39
|
+
if (entity === undefined || entity === '.generic') {
|
|
40
|
+
epath = undefined;
|
|
41
|
+
} else {
|
|
42
|
+
// Access the action.js file for the certain entity to get the path
|
|
43
|
+
const entityPath = `${adaptdir}/entities/${entity}/action.json`;
|
|
44
|
+
const actionJSON = require(entityPath);
|
|
45
|
+
actionJSON.actions.forEach((action) => {
|
|
46
|
+
if (action.name === funcName) {
|
|
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
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return epath;
|
|
61
|
+
}
|
|
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
|
+
|
|
74
|
+
function readFileUsingLib(filename, descriptionObj, workflowObj, functionList) {
|
|
75
|
+
// read the file
|
|
76
|
+
const aFile = fs.readFileSync(filename, 'utf8');
|
|
77
|
+
// parsing the file to get the function and class declarations.
|
|
78
|
+
const aFileFuncArgs = acorn.parse(aFile, { ecmaVersion: 2020 });
|
|
79
|
+
|
|
80
|
+
let callName = 'identifyRequest';
|
|
81
|
+
// Looping through all the declarations parsed:
|
|
82
|
+
aFileFuncArgs.body.forEach((e) => {
|
|
83
|
+
// Getting only the class declaration as it has our required functions.
|
|
84
|
+
if (e.type === 'ClassDeclaration') {
|
|
85
|
+
const methodDefinition = e.body;
|
|
86
|
+
methodDefinition.body.forEach((method) => {
|
|
87
|
+
// Getting method name and its params in the class.
|
|
88
|
+
const funcName = method.key.name;
|
|
89
|
+
const funcArgs = [];
|
|
90
|
+
method.value.params.forEach((param) => {
|
|
91
|
+
if (param.type === 'Identifier') {
|
|
92
|
+
funcArgs.push(param.name);
|
|
93
|
+
} else if (param.type === 'RestElement') {
|
|
94
|
+
funcArgs.push(`...${param.argument.name}`);
|
|
95
|
+
} else {
|
|
96
|
+
const args = `${param.left.name} = ${param.right.raw}`;
|
|
97
|
+
funcArgs.push(args);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Getting the entity for the method:
|
|
102
|
+
const callList = [];
|
|
103
|
+
method.value.body.body.forEach((statement) => {
|
|
104
|
+
recurseCallExpressions(statement, callList);
|
|
105
|
+
});
|
|
106
|
+
const requests = [];
|
|
107
|
+
for (let i = 0; i < callList.length; i += 1) {
|
|
108
|
+
if (callList[i].callee.property && callList[i].callee.property.name === callName) {
|
|
109
|
+
requests.push(callList[i]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (requests.length > 0) {
|
|
113
|
+
const expr = requests[0];
|
|
114
|
+
if (expr.arguments.length < 2) {
|
|
115
|
+
throw new Error(`Bad inputs in method ${funcName}`);
|
|
116
|
+
}
|
|
117
|
+
const entity = expr.arguments[0].value;
|
|
118
|
+
const actionName = expr.arguments[1].value;
|
|
119
|
+
if (expr !== undefined && (expr.arguments[0].type !== 'Literal' || expr.arguments[1].type !== 'Literal')) {
|
|
120
|
+
const param1 = method.value.params[0];
|
|
121
|
+
const param2 = method.value.params[1];
|
|
122
|
+
if (param1.type !== 'Identifier' || param2.type !== 'Identifier'
|
|
123
|
+
|| expr.arguments[0].type !== 'Identifier' || expr.arguments[1].type !== 'Identifier'
|
|
124
|
+
|| param1.name !== expr.arguments[0].name || param2.name !== expr.arguments[1].name) {
|
|
125
|
+
throw new Error(`identifyRequest proxy method ${funcName} unknown format`);
|
|
126
|
+
} else if (callName !== 'identifyRequest') {
|
|
127
|
+
throw new Error(`MethodDocumentor not yet programmed to handle multiple helper methods: 1) ${callName}, 2) ${funcName}`);
|
|
128
|
+
}
|
|
129
|
+
callName = funcName;
|
|
130
|
+
}
|
|
131
|
+
const entityPath = getPathFromEntity(entity, actionName);
|
|
132
|
+
|
|
133
|
+
// Creating and storing the object for the method.
|
|
134
|
+
if (entityPath !== undefined) {
|
|
135
|
+
functionList.push(
|
|
136
|
+
createObjectForFunction(
|
|
137
|
+
funcName,
|
|
138
|
+
funcArgs,
|
|
139
|
+
entityPath,
|
|
140
|
+
descriptionObj[funcName],
|
|
141
|
+
workflowObj[funcName]
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function readJSONFile(filename, descriptionObj, workflowObj) {
|
|
152
|
+
// Accessing the JSON file.
|
|
153
|
+
const phJSON = require(filename);
|
|
154
|
+
// Getting the methods array.
|
|
155
|
+
const methodArray = phJSON.methods;
|
|
156
|
+
methodArray.forEach((methodName) => {
|
|
157
|
+
// Getting the method description and workflow:
|
|
158
|
+
const funcName = methodName.name;
|
|
159
|
+
descriptionObj[funcName] = methodName.summary ? methodName.summary : methodName.description;
|
|
160
|
+
workflowObj[funcName] = methodName.task ? 'Yes' : 'No';
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function readMDFile(filename, functionList) {
|
|
165
|
+
// Reading in the .md file and creating an array with each line as an element.
|
|
166
|
+
const mdFile = fs.readFileSync(filename, 'utf-8');
|
|
167
|
+
const fileSplit = mdFile.split('\n');
|
|
168
|
+
// Storing the data that should added later to the updated data.
|
|
169
|
+
const linesToAddLater = [];
|
|
170
|
+
let index = fileSplit.length - 1;
|
|
171
|
+
|
|
172
|
+
// Removing all the blank lines at the end of the file.
|
|
173
|
+
if (fileSplit[index] === '') {
|
|
174
|
+
while (fileSplit[index] === '') {
|
|
175
|
+
linesToAddLater.push(fileSplit.pop());
|
|
176
|
+
index -= 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Checking if the last 2 lines are <br> and </table>. If not, the file is corrupted and the
|
|
181
|
+
// data at the end of the file should be fixed.
|
|
182
|
+
if (fileSplit[index] === '<br>' || fileSplit[index - 1] === '</table>') {
|
|
183
|
+
// Storing <br> and </table> to add later.
|
|
184
|
+
linesToAddLater.push(fileSplit.pop());
|
|
185
|
+
linesToAddLater.push(fileSplit.pop());
|
|
186
|
+
index -= 2;
|
|
187
|
+
} else {
|
|
188
|
+
console.log('The file has bad content at the end.');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// if (fileSplit[index] !== '<br>' && fileSplit[index - 1] !== '</table>') {
|
|
192
|
+
// console.log('The file has bad content at the end.');
|
|
193
|
+
// return;
|
|
194
|
+
// } else {
|
|
195
|
+
// // Storing <br> and </table> to add later.
|
|
196
|
+
// linesToAddLater.push(fileSplit.pop());
|
|
197
|
+
// linesToAddLater.push(fileSplit.pop());
|
|
198
|
+
// index -= 2;
|
|
199
|
+
// }
|
|
200
|
+
|
|
201
|
+
// Removing all the lines until the header tags are reached.
|
|
202
|
+
while (!fileSplit[index].includes('<th')) {
|
|
203
|
+
fileSplit.pop();
|
|
204
|
+
index -= 1;
|
|
205
|
+
}
|
|
206
|
+
// Adding </tr> for the header row, because it got removed in the above loop.
|
|
207
|
+
fileSplit.push(' </tr>');
|
|
208
|
+
|
|
209
|
+
// Creating the tags for each method to be appended to the file.
|
|
210
|
+
const tdBeginTag = ' <td style="padding:15px">';
|
|
211
|
+
const tdEndTag = '</td>';
|
|
212
|
+
|
|
213
|
+
functionList.forEach((func) => {
|
|
214
|
+
const signCommand = `${tdBeginTag}${func.method_signature}${tdEndTag}`;
|
|
215
|
+
const descCommand = `${tdBeginTag}${func.description}${tdEndTag}`;
|
|
216
|
+
const pathCommand = `${tdBeginTag}${func.path}${tdEndTag}`;
|
|
217
|
+
const workflowCommand = `${tdBeginTag}${func.workflow}${tdEndTag}`;
|
|
218
|
+
fileSplit.push(' <tr>');
|
|
219
|
+
fileSplit.push(signCommand);
|
|
220
|
+
fileSplit.push(descCommand);
|
|
221
|
+
fileSplit.push(pathCommand);
|
|
222
|
+
fileSplit.push(workflowCommand);
|
|
223
|
+
fileSplit.push(' </tr>');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Adding </table> and <br> at the end of the file to complete the table and the file.
|
|
227
|
+
while (linesToAddLater.length > 0) {
|
|
228
|
+
fileSplit.push(linesToAddLater.pop());
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Writing all the content back into the file.
|
|
232
|
+
fs.writeFileSync(filename, fileSplit.join('\n'), {
|
|
233
|
+
encoding: 'utf-8',
|
|
234
|
+
flag: 'w'
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function getFileInfo() {
|
|
239
|
+
// If files don't exist:
|
|
240
|
+
if (!fs.existsSync(`${adaptdir}/adapter.js`)) {
|
|
241
|
+
console.log('Missing - utils/adapter.js');
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (!fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
245
|
+
console.log('Missing - pronghorn.json');
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (!fs.existsSync(`${adaptdir}/CALLS.md`)) {
|
|
249
|
+
console.log('Missing - CALLS.md');
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const descriptionObj = {};
|
|
254
|
+
const workflowObj = {};
|
|
255
|
+
|
|
256
|
+
// Get the method descriptions and the workflow values from pronghorn.json file.
|
|
257
|
+
readJSONFile(`${adaptdir}/pronghorn.json`, descriptionObj, workflowObj);
|
|
258
|
+
|
|
259
|
+
// Get the method signature, entity path and create an object that contains all the info regarding
|
|
260
|
+
// the method and push it to the functionList array.
|
|
261
|
+
const functionList = [];
|
|
262
|
+
readFileUsingLib(
|
|
263
|
+
`${adaptdir}/adapter.js`,
|
|
264
|
+
descriptionObj,
|
|
265
|
+
workflowObj,
|
|
266
|
+
functionList
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// createMarkDown(functionList);
|
|
270
|
+
readMDFile(`${adaptdir}/CALLS.md`, functionList);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
getFileInfo();
|