profoundjs 6.2.0 → 6.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.
@@ -0,0 +1,17 @@
1
+
2
+ # Profound API Samples
3
+
4
+ A sample Profound API program. Server-side API logic is defined in low-code and JavaScript. A client-side program exists to demonstrate calling the API end point.
5
+
6
+ ## Sample GET, POST, PUT, DELETE, and Grid Request
7
+
8
+ Run the sample user interface by clicking either
9
+ * Launch > Launch App in Browser Tab
10
+ * Launch > Launch App in IDE
11
+
12
+ ## Files
13
+ * APISample.api.json - the server-side logic for the API endpoints, as Low Code steps
14
+ * APISample.js - program logic for the sample user interface to interact with the APIs
15
+ * APISample.json - sample user interface to interact with the APIs
16
+ * hobbyshop.csv - sample data file
17
+ * readCSVFile.js - sample module to handle reading and writing to the data file. Used in Low Code steps.
@@ -0,0 +1,6 @@
1
+ 1,Nintendo Switch,200,8
2
+ 2,AC Ambient,100 ,6
3
+ 3,XBOX one,120,3
4
+ 4,Sega Saturn,120,3
5
+ 5,Playstation 3,100,5
6
+ 6,bicycle gears,16,18
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ /**
3
+ * A utility function to read a CSV file and output its contents in a pre-determined format.
4
+ */
5
+ const fs = require("fs"); // filestream module
6
+ const readline = require("readline"); // line-by-line reading module
7
+
8
+ /**
9
+ * Read a file line by line and output an object with its contents, with each field as properties of the object.
10
+ * @param {String} filename
11
+ * @param {Number} rowID
12
+ * @returns {Object}
13
+ */
14
+ async function fileRead(filename, rowID = 0) {
15
+ let fLength = 0;
16
+ const lData = [];
17
+ let lTemp = null;
18
+ // Start a file stream to read the file line-by-line
19
+ const fstream = fs.createReadStream(filename);
20
+ const linereader = readline.createInterface({
21
+ input: fstream,
22
+ crlfDelay: Infinity // used to identify all \r\n entries in the file as single line breaks
23
+ });
24
+
25
+ // Start reading the lines of the file
26
+ for await (const line of linereader) {
27
+ fLength++;
28
+ if (rowID == 0) { // read the whole file, parse each line into arrays
29
+ lTemp = line.split(",");
30
+ lData.push({ ID: lTemp[0], Name: lTemp[1], Price: lTemp[2], Quantity: lTemp[3] });
31
+ }
32
+ else if (fLength == rowID) {
33
+ lTemp = line.split(",");
34
+ lData.push({ ID: lTemp[0], Name: lTemp[1], Price: lTemp[2], Quantity: lTemp[3] });
35
+ }
36
+ };
37
+
38
+ return { length: fLength, data: lData };
39
+ }
40
+
41
+ /**
42
+ * Read a file line by line, changing the specified line, and then write the data back to the file.
43
+ * Return a message indicating which row was updated.
44
+ * The original file is changed.
45
+ * @param {String} filename
46
+ * @param {Number} rowID
47
+ * @returns {String}
48
+ */
49
+ async function fileUpdate(filename, rowID, data) {
50
+ let fLength = 0;
51
+ // Start a file stream to read the file line-by-line
52
+ const fstream = fs.createReadStream(filename);
53
+ const linereader = readline.createInterface({
54
+ input: fstream,
55
+ crlfDelay: Infinity // used to identify all \r\n entries in the file as single line breaks
56
+ });
57
+
58
+ let strUpdated = "";
59
+
60
+ // Start reading the lines of the file
61
+ for await (const line of linereader) {
62
+ fLength++;
63
+ if (fLength == rowID) {
64
+ strUpdated += fLength + "," + data + "\n"; // update the specific line if found
65
+ }
66
+ else strUpdated += line + "\n";
67
+ };
68
+ linereader.close();
69
+ fstream.close();
70
+
71
+ // remove the last entry of \n
72
+ strUpdated = strUpdated.substring(0, strUpdated.length - 1);
73
+
74
+ const message = await new Promise((resolve, reject) => {
75
+ // rewrite the file with the updated data
76
+ fs.writeFile(filename, strUpdated, (err) => {
77
+ if (err) reject(err);
78
+ else resolve("Row ID: " + iID + "\nData Updated: " + data);
79
+ });
80
+ });
81
+
82
+ return message;
83
+ }
84
+
85
+ /**
86
+ * Read a file line by line and build a string with the file contents, with the line specified by rowID removed.
87
+ * Write the new string to the file, overwriting the original file.
88
+ * Return a message indicating which row was deleted.
89
+ * @param {String} filename
90
+ * @param {Number} rowID
91
+ * @returns {String}
92
+ */
93
+ async function lineDelete(filename, rowID) {
94
+ let iCol = 0;
95
+ let fLength = 0;
96
+ let strUpdated = "";
97
+ let strTemp = "";
98
+ // Start a file stream to read the file line-by-line
99
+ const fstream = fs.createReadStream(filename);
100
+ const linereader = readline.createInterface({
101
+ input: fstream,
102
+ crlfDelay: Infinity // used to identify all \r\n entries in the file as single line breaks
103
+ });
104
+
105
+ // Start reading the lines of the file
106
+ for await (const line of linereader) {
107
+ fLength++;
108
+ if (fLength < rowID) { // Copy the line as is if it's not the row ID requested
109
+ strUpdated += line + "\n";
110
+ }
111
+ else if (fLength > rowID) { // Update the first column to reflect the correct line
112
+ iCol = line.indexOf(","); // find first occurence of , as the first column
113
+ strTemp = line.substring(iCol, line.length); // move the , and the data to temp string
114
+ strUpdated += (fLength - 1) + strTemp + "\n"; // add the line and its updated column number
115
+ }
116
+ };
117
+ linereader.close();
118
+ fstream.close();
119
+
120
+ // remove the last entry of \n
121
+ strUpdated = strUpdated.substring(0, strUpdated.length - 1);
122
+
123
+ // Write the strUpdated string to the file at filename:
124
+ const message = new Promise((resolve, reject) => {
125
+ fs.writeFile(filename, strUpdated, (err) => {
126
+ if (err) reject(err);
127
+ else resolve("Row " + rowID + " deleted.");
128
+ });
129
+ });
130
+
131
+ return message;
132
+ }
133
+
134
+ exports.fileRead = fileRead;
135
+ exports.fileUpdate = fileUpdate;
136
+ exports.lineDelete = lineDelete;
Binary file
@@ -3,7 +3,7 @@
3
3
 
4
4
  /*
5
5
  Discovers and removes additional components that exist outside of the package installation directory.
6
-
6
+
7
7
  It's used by Profound Installer
8
8
 
9
9
  Any changes to the behavior may require changes to the "install_info.json" file or Profound Installer.
@@ -15,9 +15,8 @@ const readline = require("readline");
15
15
 
16
16
  const IBMi = iutils.isIBMi();
17
17
 
18
- (async () => {
18
+ (async() => {
19
19
  try {
20
-
21
20
  // Parse arguments.
22
21
  const argDefs = {
23
22
  alias: {
@@ -39,7 +38,7 @@ const IBMi = iutils.isIBMi();
39
38
 
40
39
  // Show help and quit, if requested.
41
40
  if (args["help"] === true) {
42
- const HELP = `Usage: node removeExtraComponents.js [OPTION]
41
+ const HELP = `Usage: node removeExtraComponents.js [OPTION]
43
42
  -h, --help Print this help and exit.
44
43
  -d, --dry-run Report what items would be removed, without removing them.
45
44
  -s, --silent Bypass confirmation prompt.
@@ -170,7 +169,6 @@ It is intended to be used before uninstalling the package via NPM.
170
169
  }
171
170
  console.log("Removal of extra components complete.");
172
171
  process.stdin.destroy();
173
-
174
172
  }
175
173
  catch (error) {
176
174
  process.stdin.destroy();
@@ -194,7 +192,7 @@ function exec(command, quiet = false) {
194
192
  const opts = {
195
193
  env: {
196
194
  QIBM_USE_DESCRIPTOR_STDIO: "Y",
197
- QIBM_MULTI_THREADED: "N",
195
+ QIBM_MULTI_THREADED: "N"
198
196
  },
199
197
  stdio: "pipe",
200
198
  windowsHide: true
package/setup/setup.js CHANGED
@@ -38,7 +38,7 @@ let logFile;
38
38
 
39
39
  let SILENT_MODE = false;
40
40
 
41
- (async () => {
41
+ (async() => {
42
42
  try {
43
43
  // Parse arguments.
44
44
  const args = minimist(
@@ -63,7 +63,7 @@ let SILENT_MODE = false;
63
63
  "ibmi-instance-node-path",
64
64
  "nodegit-version"
65
65
  ],
66
- unknown: function (arg) {
66
+ unknown: function(arg) {
67
67
  console.error("Unknown argument:", arg);
68
68
  process.exit(1);
69
69
  }
@@ -288,6 +288,13 @@ let SILENT_MODE = false;
288
288
  log("Copying pjssamples.");
289
289
  copyDir(path.join(__dirname, "modules", "pjssamples"), path.join(deployDir, "modules"));
290
290
 
291
+ // Create PAPI samples directory
292
+ if (directoryExists(path.join(deployDir, "modules", "papisamples"))) {
293
+ fs.removeSync(path.join(deployDir, "modules", "papisamples"));
294
+ }
295
+ log("Copying papisamples.");
296
+ copyDir(path.join(__dirname, "modules", "papisamples"), path.join(deployDir, "modules"));
297
+
291
298
  // Create store_credentials.js.
292
299
  if (fileExists(path.join(deployDir, "store_credentials.js"))) {
293
300
  log("store_credentials.js file exists.");
@@ -306,6 +313,17 @@ let SILENT_MODE = false;
306
313
  log("store_options.js created.");
307
314
  }
308
315
 
316
+ // Begin OAuth2 requirements.
317
+ // Create encrypt_client_file.js.
318
+ if (fileExists(path.join(deployDir, "encrypt_client_file.js"))) {
319
+ log("encrypt_client_file.js file exists.");
320
+ }
321
+ else {
322
+ copyFile(path.join(__dirname, "encrypt_client_file.js"), deployDir, "utf8");
323
+ log("encrypt_client_file.js created.");
324
+ }
325
+ // End OAuth2 requirements.
326
+
309
327
  // Create call.js.
310
328
  if (fileExists(path.join(deployDir, "call.js"))) {
311
329
  log("call.js file exists.");
@@ -414,17 +432,17 @@ let SILENT_MODE = false;
414
432
  }
415
433
  })();
416
434
 
417
- function log (...args) {
435
+ function log(...args) {
418
436
  console.log(...args);
419
437
  logToFile(...args);
420
438
  }
421
439
 
422
- function logError (...args) {
440
+ function logError(...args) {
423
441
  console.error(...args);
424
442
  logToFile(...args);
425
443
  }
426
444
 
427
- function logToFile (...args) {
445
+ function logToFile(...args) {
428
446
  if (SILENT_MODE) {
429
447
  return;
430
448
  }
@@ -433,7 +451,7 @@ function logToFile (...args) {
433
451
  fs.writeFileSync(logFile, output, { flag: "a" });
434
452
  }
435
453
 
436
- function die () {
454
+ function die() {
437
455
  logError(`\n${RED}Profound.js installation failed.${RESET}`);
438
456
  if (!SILENT_MODE) {
439
457
  console.error(`${RED}See installation log:${RESET} ${logPath}\n`);
@@ -441,11 +459,11 @@ function die () {
441
459
  process.exit(1);
442
460
  }
443
461
 
444
- function copyDir (dir, destinationDir) {
462
+ function copyDir(dir, destinationDir) {
445
463
  const dirName = path.basename(dir);
446
464
  fs.mkdirSync(path.join(destinationDir, dirName));
447
465
  const files = fs.readdirSync(dir);
448
- files.forEach(function (file, index) {
466
+ files.forEach(function(file, index) {
449
467
  if (fs.lstatSync(path.join(dir, file)).isDirectory()) { // recurse
450
468
  copyDir(path.join(dir, file), path.join(destinationDir, dirName));
451
469
  }
@@ -455,7 +473,7 @@ function copyDir (dir, destinationDir) {
455
473
  });
456
474
  }
457
475
 
458
- function copyFile (file, destination, type) {
476
+ function copyFile(file, destination, type) {
459
477
  if (type == null) type = "binary";
460
478
  let toFile;
461
479
  if (directoryExists(destination)) {
@@ -468,9 +486,9 @@ function copyFile (file, destination, type) {
468
486
  fs.writeFileSync(toFile, content, type);
469
487
  }
470
488
 
471
- function createPuiscreens (deployDir) {
489
+ function createPuiscreens(deployDir) {
472
490
  const targetPuiScreensFile = path.join(deployDir, "modules", "puiscreens.json");
473
- function copyFileOldVersionIs (version, compareStr) {
491
+ function copyFileOldVersionIs(version, compareStr) {
474
492
  compareStr = compareStr || "=";
475
493
  log("Found Standard puiscreens.json file version " + compareStr + " " + version + ", replacing with current version...");
476
494
  copyFile(path.join(__dirname, "modules", "puiscreens.json"), targetPuiScreensFile, "utf8");
@@ -598,7 +616,7 @@ function createPuiscreens (deployDir) {
598
616
  }
599
617
  }
600
618
 
601
- function directoryExists (dir) {
619
+ function directoryExists(dir) {
602
620
  let exists = false;
603
621
  try {
604
622
  const stat = fs.statSync(dir);
@@ -610,7 +628,7 @@ function directoryExists (dir) {
610
628
  return exists;
611
629
  }
612
630
 
613
- function fileExists (file) {
631
+ function fileExists(file) {
614
632
  let exists = false;
615
633
  try {
616
634
  const stat = fs.statSync(file);
@@ -622,7 +640,7 @@ function fileExists (file) {
622
640
  return exists;
623
641
  }
624
642
 
625
- function runCommand (command, switches) {
643
+ function runCommand(command, switches) {
626
644
  log("Executing IBM i command: " + command);
627
645
  const args = [command];
628
646
  if (typeof switches == "string") {