From 2fc206e837be807265fddc5188f8d227738b3258 Mon Sep 17 00:00:00 2001
From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com>
Date: Tue, 11 Feb 2020 10:33:17 -0600
Subject: [PATCH] refactor: Remove ixml refs in ProgramCall
---
lib/Deprecated.js | 14 +++++++++-
lib/ProgramCall.js | 70 +++++++++++++++++++++++++++++-----------------
lib/ixml.js | 29 -------------------
3 files changed, 57 insertions(+), 56 deletions(-)
diff --git a/lib/Deprecated.js b/lib/Deprecated.js
index 5483c80d..9027a832 100644
--- a/lib/Deprecated.js
+++ b/lib/Deprecated.js
@@ -23,6 +23,8 @@
// previous versions, but will throw a warning message. When we no longer want to support calling
// these methods through these deprecated class names, we can simple disable this file.
+/* eslint-disable max-classes-per-file */
+
const deprecate = require('depd');
const iPgmDeprecate = deprecate('iPgm');
@@ -66,6 +68,11 @@ class iPgm {
* @param {*} inDs
*/
addParam(data, type, options, inDs) {
+ if (!Array.isArray(data) && !type) {
+ iPgmDeprecate('defaulting parameter type to 1024a has been deprecated. You should specify a type instead.');
+ // eslint-disable-next-line no-param-reassign
+ type = '1024a';
+ }
iPgmDeprecate('As of v1.0, \'iPgm.addParam()\' is deprecated. Please use \'ProgramCall.addParam()\' instead.');
return this.ProgramCall.addParam(data, type, options, inDs);
}
@@ -76,7 +83,12 @@ class iPgm {
* @param {string} type
* @param {object} [options]
*/
- addReturn(data, type, options) {
+ addReturn(data, type = '1024a', options) {
+ if (!type) {
+ iPgmDeprecate('defaulting return type to 1024a has been deprecated. You should specify a type instead.');
+ // eslint-disable-next-line no-param-reassign
+ type = '1024a';
+ }
iPgmDeprecate('As of v1.0, \'iPgm.addReturn()\' is deprecated. Please use \'ProgramCall.addParam()\' instead.');
return this.ProgramCall.addReturn(data, type, options);
}
diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js
index f748560e..6b05a8e1 100644
--- a/lib/ProgramCall.js
+++ b/lib/ProgramCall.js
@@ -16,8 +16,6 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-const iXml = require('./ixml');
-
class ProgramCall {
/**
* @description creates a new ProgramCall object
@@ -25,16 +23,11 @@ class ProgramCall {
* @param {string} program
* @param {object} [options]
*/
- constructor(program, options) {
- if (options && typeof options === 'object') {
- // add options if they exist, or empty string if they don't
- this.xml = iXml.iXmlNodePgmOpen(program,
- options.lib !== undefined ? options.lib : '',
- options.func !== undefined ? options.func : '',
- options.error !== undefined ? options.error : '');
- } else {
- this.xml = iXml.iXmlNodePgmOpen(program, '', '', '');
- }
+ constructor(program, options = {}) {
+ this.xml = ``;
}
/**
@@ -51,28 +44,46 @@ class ProgramCall {
opt = type;
} else {
opt = options;
+ if (!type) {
+ throw new Error('Specifying the parameter type is required.');
+ }
}
if (!inDs) { // In recursive mode, if it is an element in DS, then no or needed.
- this.xml += iXml.iXmlNodeParmOpen(opt);
+ this.xml += ' options
+ if (opt.io) { this.xml += ` io='${opt.io}'`; }
+ if (opt.by) { this.xml += ` by='${opt.by}'`; }
+ }
+ this.xml += '>';
}
- if (Array.isArray(data)) { // If it is a struct parameter, recursivly parse its children.
- if (opt) {
- this.xml += iXml.iXmlNodeDsOpen(opt.dim, opt.dou, opt.len, opt.data);
- } else {
- this.xml += iXml.iXmlNodeDsOpen('', '', '', '');
+ if (Array.isArray(data)) { // If it is a struct parameter, recursively parse its children.
+ this.xml += ' options
+ if (opt.dim) { this.xml += ` dim='${opt.dim}'`; }
+ if (opt.dou) { this.xml += ` dou='${opt.dou}'`; }
+ if (opt.len) { this.xml += ` len='${opt.len}'`; }
+ if (opt.data) { this.xml += ` data='${opt.data}'`; }
}
+ this.xml += '>';
+
for (let i = 0; i < data.length; i += 1) {
this.addParam(data[i][0], data[i][1], data[i][2], true);
}
- this.xml += iXml.iXmlNodeDsClose();
+ this.xml += '';
} else { // A simple parameter
- this.xml += iXml.iXmlNodeDataOpen(type, opt) + data + iXml.iXmlNodeDataClose();
+ this.xml += ` options
+ Object.keys(opt).forEach((key) => {
+ this.xml += ` ${key}='${opt[key]}'`;
+ });
+ }
+ this.xml += `>${data}`;
}
if (!inDs) { // In recursive mode, if it is an element in DS, then no or needed.
- this.xml += iXml.iXmlNodeParmClose();
+ this.xml += '';
}
}
@@ -83,13 +94,20 @@ class ProgramCall {
* @param {object} [options]
*/
addReturn(data, type, options = null) {
- this.xml += iXml.iXmlNodeReturnOpen();
+ if (!type) {
+ throw new Error('Specifying the return type is required.');
+ }
+ this.xml += '';
+
if (options && typeof options === 'object') {
- this.xml += iXml.iXmlNodeDataOpen(type, options);
+ this.xml += ` {
+ this.xml += ` ${key}='${options[key]}'`;
+ });
} else {
- this.xml += iXml.iXmlNodeDataOpen(type);
+ this.xml += `${data}`;
}
/**
@@ -97,7 +115,7 @@ class ProgramCall {
* @returns {string} - the generated program XML
*/
toXML() {
- return this.xml + iXml.iXmlNodePgmClose();
+ return `${this.xml}`;
}
}
diff --git a/lib/ixml.js b/lib/ixml.js
index 6bbcb9d4..3d51b6b9 100644
--- a/lib/ixml.js
+++ b/lib/ixml.js
@@ -35,49 +35,20 @@ module.exports.iXmlNodeScriptOpen = () => '';
module.exports.iXmlNodeScriptClose = () => '';
-module.exports.iXmlNodePgmOpen = (xname, xlib, xfunc, xerror) => ``;
-module.exports.iXmlNodePgmClose = () => '';
-module.exports.iXmlNodeParmOpen = (opt) => {
- if (!(opt && typeof opt === 'object')) {
- return '';
- }
-
- const io = (opt.io) ? iXmlAttrDefault('io', opt.io, '') : '';
- const by = (opt.by) ? iXmlAttrDefault('by', opt.by, '') : '';
- return ``;
-};
-module.exports.iXmlNodeParmClose = () => '';
-module.exports.iXmlNodeReturnOpen = () => '';
-module.exports.iXmlNodeReturnClose = () => '';
module.exports.iXmlNodeOverlayOpen = (xio, xoffset, xtop) => ``;
module.exports.iXmlNodeOverlayClose = () => '';
-module.exports.iXmlNodeDsOpen = (xdim, xdou, xlen, xdata) => ``;
-
-module.exports.iXmlNodeDsClose = () => '';
-module.exports.iXmlNodeDataOpen = (xtype, options) => {
- let result = ` {
- result += iXmlAttrDefault(key, options[key], '1024a');
- });
- }
-
- result += '>';
- return result;
-};
-module.exports.iXmlNodeDataClose = () => '';
module.exports.iXmlNodeCmdOpen = (xexec, xhex, xbefore, xafter, xerror) => ``;