@itentialopensource/adapter-db_postgresql 0.2.1 → 1.0.1

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.
@@ -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();
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  /* @copyright Itential, LLC 2019 */
3
3
 
4
- const fs = require('fs-extra');
5
4
  const path = require('path');
5
+ const fs = require('fs-extra');
6
6
 
7
7
  async function createBundle(adapterOldDir) {
8
8
  // set directories
@@ -15,7 +15,6 @@ async function createBundle(adapterOldDir) {
15
15
  const shortenedName = originalName.replace('adapter-', '');
16
16
  const artifactName = originalName.replace('adapter', 'bundled-adapter');
17
17
 
18
-
19
18
  const adapterNewDir = path.join(artifactDir, 'bundles', 'adapters', originalName);
20
19
  fs.ensureDirSync(adapterNewDir);
21
20
 
@@ -121,7 +120,7 @@ async function createBundle(adapterOldDir) {
121
120
 
122
121
  // Run the commands in parallel
123
122
  try {
124
- await Promise.all(ops.map(async op => op()));
123
+ await Promise.all(ops.map(async (op) => op()));
125
124
  } catch (e) {
126
125
  throw new Error(e);
127
126
  }
@@ -134,18 +133,14 @@ async function createBundle(adapterOldDir) {
134
133
  }
135
134
 
136
135
  async function artifactize(entryPathToAdapter) {
137
- try {
138
- const truePath = path.resolve(entryPathToAdapter);
139
- const packagePath = path.join(truePath, 'package');
140
- // remove adapter from package and move bundle in
141
- const pathObj = await createBundle(packagePath);
142
- const { bundlePath } = pathObj;
143
- fs.removeSync(packagePath);
144
- fs.moveSync(bundlePath, packagePath);
145
- return 'Bundle successfully created and old folder system removed';
146
- } catch (e) {
147
- throw e;
148
- }
136
+ const truePath = path.resolve(entryPathToAdapter);
137
+ const packagePath = path.join(truePath, 'package');
138
+ // remove adapter from package and move bundle in
139
+ const pathObj = await createBundle(packagePath);
140
+ const { bundlePath } = pathObj;
141
+ fs.removeSync(packagePath);
142
+ fs.moveSync(bundlePath, packagePath);
143
+ return 'Bundle successfully created and old folder system removed';
149
144
  }
150
145
 
151
146
  module.exports = { createBundle, artifactize };
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  /* @copyright Itential, LLC 2019 */
3
3
 
4
- const fs = require('fs-extra');
5
4
  const path = require('path');
6
5
  const { spawnSync } = require('child_process');
7
- const { createBundle } = require('./artifactize.js');
6
+ const fs = require('fs-extra');
7
+ const { createBundle } = require('./artifactize');
8
8
 
9
9
  const nodeEntryPath = path.resolve('.');
10
10
  createBundle(nodeEntryPath).then((pathObj) => {
File without changes
@@ -0,0 +1,20 @@
1
+ const fs = require('fs');
2
+
3
+ /**
4
+ * This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
5
+ * commit/push something that has issues
6
+ */
7
+
8
+ const precommitPath = '.git/hooks/pre-commit';
9
+ const prepushPath = '.git/hooks/pre-push';
10
+ fs.unlink(precommitPath, (err) => {
11
+ if (err && err.code !== 'ENOENT') {
12
+ console.log(`${err.message}`);
13
+ }
14
+ });
15
+
16
+ fs.unlink(prepushPath, (err) => {
17
+ if (err && err.code !== 'ENOENT') {
18
+ console.log(`${err.message}`);
19
+ }
20
+ });
package/utils/setup.js CHANGED
File without changes
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  /* @copyright Itential, LLC 2019 */
3
3
 
4
+ const execute = require('child_process').exec;
4
5
  const fs = require('fs-extra');
5
6
  const rl = require('readline-sync');
6
- const execute = require('child_process').exec;
7
7
 
8
8
  /**
9
9
  * This script will determine the type of integration test to run
@@ -47,11 +47,11 @@ function replaceTestVars(test) {
47
47
  let intTest = fs.readFileSync(test, 'utf8');
48
48
 
49
49
  // replace stub variable but check if it exists first
50
- let sindex = intTest.indexOf('const stub');
50
+ let sindex = intTest.indexOf('samProps.stub');
51
51
  let eindex = intTest.indexOf(';', sindex);
52
52
  let replStr = intTest.substring(sindex, eindex + 1);
53
53
  if (sindex > -1) {
54
- intTest = intTest.replace(replStr, `const stub = ${stub};`);
54
+ intTest = intTest.replace(replStr, `samProps.stub = ${stub};`);
55
55
  }
56
56
 
57
57
  // replace isRapidFail variable but check if it exists first
@@ -71,46 +71,46 @@ function replaceTestVars(test) {
71
71
  }
72
72
 
73
73
  // replace host variable
74
- sindex = intTest.indexOf('const host');
74
+ sindex = intTest.indexOf('samProps.host');
75
75
  eindex = intTest.indexOf(';', sindex);
76
76
  replStr = intTest.substring(sindex, eindex + 1);
77
- intTest = intTest.replace(replStr, `const host = '${host}';`);
77
+ intTest = intTest.replace(replStr, `samProps.host = '${host}';`);
78
78
 
79
79
  // replace username variable
80
- sindex = intTest.indexOf('const username');
80
+ sindex = intTest.indexOf('samProps.authentication.username');
81
81
  eindex = intTest.indexOf(';', sindex);
82
82
  replStr = intTest.substring(sindex, eindex + 1);
83
- intTest = intTest.replace(replStr, `const username = '${username}';`);
83
+ intTest = intTest.replace(replStr, `samProps.authentication.username = '${username}';`);
84
84
 
85
85
  // replace password variable
86
- sindex = intTest.indexOf('const password');
86
+ sindex = intTest.indexOf('samProps.authentication.password');
87
87
  eindex = intTest.indexOf(';', sindex);
88
88
  replStr = intTest.substring(sindex, eindex + 1);
89
- intTest = intTest.replace(replStr, `const password = '${password}';`);
89
+ intTest = intTest.replace(replStr, `samProps.authentication.password = '${password}';`);
90
90
 
91
91
  // replace protocol variable
92
- sindex = intTest.indexOf('const protocol');
92
+ sindex = intTest.indexOf('samProps.protocol');
93
93
  eindex = intTest.indexOf(';', sindex);
94
94
  replStr = intTest.substring(sindex, eindex + 1);
95
- intTest = intTest.replace(replStr, `const protocol = '${protocol}';`);
95
+ intTest = intTest.replace(replStr, `samProps.protocol = '${protocol}';`);
96
96
 
97
97
  // replace port variable
98
- sindex = intTest.indexOf('const port');
98
+ sindex = intTest.indexOf('samProps.port');
99
99
  eindex = intTest.indexOf(';', sindex);
100
100
  replStr = intTest.substring(sindex, eindex + 1);
101
- intTest = intTest.replace(replStr, `const port = ${port};`);
101
+ intTest = intTest.replace(replStr, `samProps.port = ${port};`);
102
102
 
103
103
  // replace sslenable variable
104
- sindex = intTest.indexOf('const sslenable');
104
+ sindex = intTest.indexOf('samProps.ssl.enabled');
105
105
  eindex = intTest.indexOf(';', sindex);
106
106
  replStr = intTest.substring(sindex, eindex + 1);
107
- intTest = intTest.replace(replStr, `const sslenable = ${sslenable};`);
107
+ intTest = intTest.replace(replStr, `samProps.ssl.enabled = ${sslenable};`);
108
108
 
109
109
  // replace sslinvalid variable
110
- sindex = intTest.indexOf('const sslinvalid');
110
+ sindex = intTest.indexOf('samProps.ssl.accept_invalid_cert');
111
111
  eindex = intTest.indexOf(';', sindex);
112
112
  replStr = intTest.substring(sindex, eindex + 1);
113
- intTest = intTest.replace(replStr, `const sslinvalid = ${sslinvalid};`);
113
+ intTest = intTest.replace(replStr, `samProps.ssl.accept_invalid_cert = ${sslinvalid};`);
114
114
 
115
115
  console.log(`Updates to ${test} complete`);
116
116
  fs.writeFileSync(test, intTest);