From 381bce88f3c32418aa659f1f6d2dec474f3deb9a Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Wed, 11 Mar 2020 12:50:49 -0500 Subject: [PATCH 01/11] refactor: ProgramCall.addParam to accept an object - add internal functions to handle ds and data nodes --- lib/ProgramCall.js | 136 +++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 43 deletions(-) diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index 71188c87..7ff9bd21 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -16,6 +16,8 @@ // 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. +/* eslint-disable no-underscore-dangle */ + class ProgramCall { /** * @description creates a new ProgramCall object @@ -31,59 +33,107 @@ class ProgramCall { } /** - * @description adds a parameter to the program XML - * @param {string | array} data - * @param {string} [type] - * @param {object} options - * @param {*} inDs - */ - addParam(data, type, options, inDs = null) { - let opt; - // DS element has no 'type', so if the second param 'type' is an Object, then it is the options. - if (Array.isArray(data)) { - opt = type; - } else { - opt = options; - if (type === undefined) { - throw new Error('Specifying the parameter type is required.'); - } + * Internal function to create nodes + * There is an open propsal to add private methods to JS. + * https://github.com/tc39/proposal-private-methods + * We should update to use private methods in the future. + * @param {string} name + * @param {string} type + * @param {string} value + * @param {object} options + */ + __addDataNode__(name, type, value, options) { + const dataName = name ? ` name='${name}'` : ''; + this.xml += ` options + if (typeof options === 'object') { + if (options.varying) { this.xml += ` varying='${options.varying.varying}'`; } + if (options.enddo) { this.xml += ` enddo='${options.enddo}'`; } + if (options.setlen) { this.xml += ` setlen='${options.setlen}'`; } + if (options.offset) { this.xml += ` offset='${options.offset}'`; } + if (options.hex) { this.xml += ` hex='${options.hex}'`; } + if (options.trim) { this.xml += ` trim='${options.trim}'`; } + if (options.next) { this.xml += ` next='${options.next}'`; } } - if (!inDs) { // In recursive mode, if it is an element in DS, then no or needed. - this.xml += ' options - if (opt.io) { this.xml += ` io='${opt.io}'`; } - if (opt.by) { this.xml += ` by='${opt.by}'`; } + this.xml += `>${value}`; + } + + /** + * Internal function to create nodes + * There is an open propsal to add private methods to JS. + * https://github.com/tc39/proposal-private-methods + * We should update to use private methods in the future. + * @param {array} ds + * @param {object} options + */ + __addDsNodes__(ds, options = {}) { + if (Array.isArray(ds[0])) { // check if we are dealing with a 2D array + for (let i = 0; i < ds.length; i += 1) { + if (!Array.isArray(ds[i][0])) { + // handles 2D array without nested DS + this.__addDataNode__(ds[i][0], ds[i][1], ds[i][2], ds[i][3]); + // eslint-disable-next-line no-continue + continue; + } + // handle nested ds + this.xml += ' options + if (options.dim) { this.xml += ` dim='${options.dim}'`; } + if (options.dou) { this.xml += ` dou='${options.dou}'`; } + if (options.len) { this.xml += ` len='${options.len}'`; } + if (options.data) { this.xml += ` data='${options.data}'`; } + this.xml += '>'; + + for (let j = 0; j < ds[i].length; j += 1) { + this.__addDsNodes__(ds[i][j], options); + } + this.xml += ''; } - this.xml += '>'; + } else { + this.__addDataNode__(ds[0], ds[1], ds[2], ds[3]); } + } - if (Array.isArray(data)) { // If it is a struct parameter, recursively parse its children. + /** + * Internal function to handle ds and data within node + * @param {object} parameter + */ + __addData__(parameter = {}) { + // adding a data structure with data nodes + if (Array.isArray(parameter.value)) { 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}'`; } - } + // append options + if (parameter.dim) { this.xml += ` dim='${parameter.dim}'`; } + if (parameter.dou) { this.xml += ` dou='${parameter.dou}'`; } + if (parameter.len) { this.xml += ` len='${parameter.len}'`; } + if (parameter.data) { this.xml += ` data='${parameter.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.__addDsNodes__(parameter.value, parameter); this.xml += ''; - } else { // A simple parameter - this.xml += ` options - Object.keys(opt).forEach((key) => { - this.xml += ` ${key}='${opt[key]}'`; - }); - } - this.xml += `>${data}`; + } else { + this.__addDataNode__(parameter.name, parameter.type, parameter.value, parameter); } + } - if (!inDs) { // In recursive mode, if it is an element in DS, then no or needed. - this.xml += ''; + /** + * @description adds a parameter to the program XML + * @param {object} parmeter + */ + addParam(parameter = {}) { + if (typeof parameter !== 'object') { + throw new Error('Expected the first parameter to be an object'); } + if (parameter.type === undefined) { + throw new Error('Expected \'type\' key on the parameter object'); + } + this.xml += ' Date: Wed, 11 Mar 2020 12:56:26 -0500 Subject: [PATCH 02/11] refactor: iPgm.addParam to call ProgramCall.addParam with an object --- lib/Deprecated.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/Deprecated.js b/lib/Deprecated.js index de696348..c1381aab 100644 --- a/lib/Deprecated.js +++ b/lib/Deprecated.js @@ -64,16 +64,40 @@ class iPgm { * @param {string | array} data * @param {string} [type] * @param {object} options - * @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'; + addParam(data, type, options) { + const parameter = {}; + + if (Array.isArray(data)) { + parameter.value = data; + parameter.type = 'ds'; + if (typeof type === 'object') { + Object.keys(type).forEach((key) => { + parameter[key] = type[key]; + }); + } + for (let i = 0; i < data.length; i += 1) { + data[i].unshift(''); // adds empty name for each data node + // eslint-disable-next-line no-param-reassign + [data[i][2], data[i][1]] = [data[i][1], data[i][2]]; // swaps values + } + } else { + parameter.value = data; + parameter.type = type; + if (!type) { + iPgmDeprecate('defaulting parameter type to 1024a has been deprecated. You should specify a type instead.'); + parameter.type = '1024a'; + } + + if (typeof options === 'object') { + Object.keys(options).forEach((key) => { + parameter[key] = options[key]; + }); + } } + iPgmDeprecate('As of v1.0, \'iPgm.addParam()\' is deprecated. Please use \'ProgramCall.addParam()\' instead.'); - return this.ProgramCall.addParam(data, type, options, inDs); + return this.ProgramCall.addParam(parameter); } /** From 2fa2ed6b7fea63fae650cfd3599011497e1f2e83 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Thu, 12 Mar 2020 11:42:34 -0500 Subject: [PATCH 03/11] test: Update ProgramCallUnit with addParam changes - addParam now accepts an object as a parameter - DS parameters are now in this format [name, type, value, options] --- test/unit/ProgamCallUnit.js | 62 +++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/test/unit/ProgamCallUnit.js b/test/unit/ProgamCallUnit.js index 9fbaaae9..0c2dba14 100644 --- a/test/unit/ProgamCallUnit.js +++ b/test/unit/ProgamCallUnit.js @@ -22,21 +22,23 @@ const { expect } = require('chai'); const { ProgramCall } = require('../../lib/itoolkit'); +// now in this format +// [name, type, value, options] const outBuf = [ - [0, '10i0'], - [0, '10i0'], - ['', '36h'], - ['', '10A'], - ['', '1A'], - ['', '1A'], - [0, '10i0'], - [0, '10i0'], + ['', '10i0', 0], + ['', '10i0', 0], + ['', '36h', ''], + ['', '10A', ''], + ['', '1A', ''], + ['', '1A', ''], + ['', '10i0', 0], + ['', '10i0', 0], ]; const errno = [ - [0, '10i0'], - [0, '10i0', { setlen: 'rec2' }], - ['', '7A'], - ['', '1A'], + ['', '10i0', 0], + ['', '10i0', 0, { setlen: 'rec2' }], + ['', '7A', ''], + ['', '1A', ''], ]; describe('ProgramCall Class Unit Tests', () => { @@ -71,7 +73,7 @@ describe('ProgramCall Class Unit Tests', () => { error: 'fast', }); - pgm.addParam(outBuf, { io: 'out' }); + pgm.addParam({ value: outBuf, io: 'out', type: 'ds' }); let expectedXML = '' + '0' @@ -81,7 +83,7 @@ describe('ProgramCall Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); - pgm.addParam(66, '10i0'); + pgm.addParam({ value: 66, type: '10i0' }); expectedXML = '' + '0' @@ -92,7 +94,7 @@ describe('ProgramCall Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); - pgm.addParam(1, '10i0'); + pgm.addParam({ value: 1, type: '10i0' }); expectedXML = '' + '0' @@ -104,7 +106,7 @@ describe('ProgramCall Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); - pgm.addParam('QCCSID', '10A'); + pgm.addParam({ value: 'QCCSID', type: '10A' }); expectedXML = '' + '0' @@ -117,7 +119,9 @@ describe('ProgramCall Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); - pgm.addParam(errno, { io: 'both', len: 'rec2' }); + pgm.addParam({ + value: errno, type: 'ds', io: 'both', len: 'rec2', + }); expectedXML = '' + '0' @@ -137,8 +141,8 @@ describe('ProgramCall Class Unit Tests', () => { it('regular contains by=\'val\'', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); - pgm.addParam('', '1A', { by: 'val' }); - pgm.addReturn('', '2A', { name: 'output' }); + pgm.addParam({ value: '', type: '1A', by: 'val' }); + pgm.addReturn('', '2A', 'output'); const lookAtXML = pgm.toXML(); expect(lookAtXML).to.match(//); @@ -148,11 +152,13 @@ describe('ProgramCall Class Unit Tests', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); const params = [ - [0, '3s0'], - [0, '7s0', { name: 'ds_fld2' }], + ['', '3s0', 0], + ['', '7s0', 0, { name: 'ds_fld2' }], ]; - pgm.addParam(params, { name: 'inds', by: 'val' }); + pgm.addParam({ + value: params, type: 'ds', name: 'inds', by: 'val', + }); pgm.addReturn('', '2A', { name: 'output' }); const lookAtXML = pgm.toXML(); @@ -162,7 +168,9 @@ describe('ProgramCall Class Unit Tests', () => { it('regular contains by=\'val\', with io=\'both\'', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); - pgm.addParam('', '1A', { by: 'val', io: 'both' }); + pgm.addParam({ + value: '', type: '1A', by: 'val', io: 'both', + }); pgm.addReturn('', '2A', { name: 'output' }); const lookAtXML = pgm.toXML(); @@ -174,11 +182,13 @@ describe('ProgramCall Class Unit Tests', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); const params = [ - [0, '3s0'], - [0, '7s0', { name: 'ds_fld2' }], + ['', '3s0', 0], + ['', '7s0', 0, { name: 'ds_fld2' }], ]; - pgm.addParam(params, { name: 'inds', by: 'val', io: 'both' }); + pgm.addParam({ + value: params, type: 'ds', name: 'inds', by: 'val', io: 'both', + }); pgm.addReturn('', '2A', { name: 'output' }); const lookAtXML = pgm.toXML(); From 4908bb29b746dd4cd43a9feaa0c9a0f9894b7156 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Thu, 12 Mar 2020 13:12:09 -0500 Subject: [PATCH 04/11] fixup! refactor: ProgramCall.addParam to accept an object --- lib/ProgramCall.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index 7ff9bd21..19f3abf9 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -126,7 +126,9 @@ class ProgramCall { if (parameter.type === undefined) { throw new Error('Expected \'type\' key on the parameter object'); } - this.xml += ' Date: Thu, 12 Mar 2020 13:13:59 -0500 Subject: [PATCH 05/11] fixup! fixup! refactor: ProgramCall.addParam to accept an object --- lib/ProgramCall.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index 19f3abf9..165f2992 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -128,7 +128,6 @@ class ProgramCall { } const nameNode = parameter.name ? ` name='${parameter.name}'` : ''; this.xml += ` Date: Tue, 17 Mar 2020 17:51:33 -0500 Subject: [PATCH 06/11] fixup! refactor: ProgramCall.addParam to accept an object --- lib/ProgramCall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index 165f2992..988e534f 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -85,7 +85,7 @@ class ProgramCall { this.xml += '>'; for (let j = 0; j < ds[i].length; j += 1) { - this.__addDsNodes__(ds[i][j], options); + this.__addDsNodes__(ds[i][j]); } this.xml += ''; } From d86b4783932a665a681f5f47b8adcbf675682e26 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Tue, 24 Mar 2020 19:11:59 -0500 Subject: [PATCH 07/11] fixup! refactor: ProgramCall.addParam to accept an object --- lib/ProgramCall.js | 103 ++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 75 deletions(-) diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index 988e534f..79dfe82f 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -33,92 +33,45 @@ class ProgramCall { } /** - * Internal function to create nodes - * There is an open propsal to add private methods to JS. - * https://github.com/tc39/proposal-private-methods - * We should update to use private methods in the future. - * @param {string} name - * @param {string} type - * @param {string} value - * @param {object} options - */ - __addDataNode__(name, type, value, options) { - const dataName = name ? ` name='${name}'` : ''; - this.xml += ` options - if (typeof options === 'object') { - if (options.varying) { this.xml += ` varying='${options.varying.varying}'`; } - if (options.enddo) { this.xml += ` enddo='${options.enddo}'`; } - if (options.setlen) { this.xml += ` setlen='${options.setlen}'`; } - if (options.offset) { this.xml += ` offset='${options.offset}'`; } - if (options.hex) { this.xml += ` hex='${options.hex}'`; } - if (options.trim) { this.xml += ` trim='${options.trim}'`; } - if (options.next) { this.xml += ` next='${options.next}'`; } - } - this.xml += `>${value}`; - } - - /** - * Internal function to create nodes + * Internal function to handle ds and data within node * There is an open propsal to add private methods to JS. * https://github.com/tc39/proposal-private-methods * We should update to use private methods in the future. - * @param {array} ds - * @param {object} options - */ - __addDsNodes__(ds, options = {}) { - if (Array.isArray(ds[0])) { // check if we are dealing with a 2D array - for (let i = 0; i < ds.length; i += 1) { - if (!Array.isArray(ds[i][0])) { - // handles 2D array without nested DS - this.__addDataNode__(ds[i][0], ds[i][1], ds[i][2], ds[i][3]); - // eslint-disable-next-line no-continue - continue; - } - // handle nested ds - this.xml += ' options - if (options.dim) { this.xml += ` dim='${options.dim}'`; } - if (options.dou) { this.xml += ` dou='${options.dou}'`; } - if (options.len) { this.xml += ` len='${options.len}'`; } - if (options.data) { this.xml += ` data='${options.data}'`; } - this.xml += '>'; - - for (let j = 0; j < ds[i].length; j += 1) { - this.__addDsNodes__(ds[i][j]); - } - this.xml += ''; - } - } else { - this.__addDataNode__(ds[0], ds[1], ds[2], ds[3]); - } - } - - /** - * Internal function to handle ds and data within node - * @param {object} parameter + * @param {object} data */ - __addData__(parameter = {}) { - // adding a data structure with data nodes - if (Array.isArray(parameter.value)) { + __addData__(data = {}) { + if (data.type === 'ds') { this.xml += ' options - if (parameter.dim) { this.xml += ` dim='${parameter.dim}'`; } - if (parameter.dou) { this.xml += ` dou='${parameter.dou}'`; } - if (parameter.len) { this.xml += ` len='${parameter.len}'`; } - if (parameter.data) { this.xml += ` data='${parameter.data}'`; } + if (data.dim) { this.xml += ` dim='${data.dim}'`; } + if (data.dou) { this.xml += ` dou='${data.dou}'`; } + if (data.len) { this.xml += ` len='${data.len}'`; } + if (data.data) { this.xml += ` data='${data.data}'`; } this.xml += '>'; - this.__addDsNodes__(parameter.value, parameter); + + for (let i = 0; i < data.fields.length; i += 1) { + this.__addData__(data.fields[i]); + } this.xml += ''; } else { - this.__addDataNode__(parameter.name, parameter.type, parameter.value, parameter); + this.xml += ` options + if (data.name) { this.xml += ` name='${data.name}'`; } + if (data.varying) { this.xml += ` varying='${data.varying}'`; } + if (data.enddo) { this.xml += ` enddo='${data.enddo}'`; } + if (data.setlen) { this.xml += ` setlen='${data.setlen}'`; } + if (data.offset) { this.xml += ` offset='${data.offset}'`; } + if (data.hex) { this.xml += ` hex='${data.hex}'`; } + if (data.trim) { this.xml += ` trim='${data.trim}'`; } + if (data.next) { this.xml += ` next='${data.next}'`; } + this.xml += `>${data.value}`; } } /** - * @description adds a parameter to the program XML - * @param {object} parmeter - */ + * @description adds a parameter to the program XML + * @param {object} parmeter + */ addParam(parameter = {}) { if (typeof parameter !== 'object') { throw new Error('Expected the first parameter to be an object'); @@ -126,9 +79,9 @@ class ProgramCall { if (parameter.type === undefined) { throw new Error('Expected \'type\' key on the parameter object'); } - const nameNode = parameter.name ? ` name='${parameter.name}'` : ''; - this.xml += ` Date: Tue, 24 Mar 2020 19:13:11 -0500 Subject: [PATCH 08/11] fixup! refactor: iPgm.addParam to call ProgramCall.addParam with an object --- lib/Deprecated.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/Deprecated.js b/lib/Deprecated.js index c1381aab..e23ad97c 100644 --- a/lib/Deprecated.js +++ b/lib/Deprecated.js @@ -68,28 +68,34 @@ class iPgm { addParam(data, type, options) { const parameter = {}; - if (Array.isArray(data)) { - parameter.value = data; + if (Array.isArray(data)) { // DS parameter parameter.type = 'ds'; - if (typeof type === 'object') { + parameter.fields = []; + + if (typeof type === 'object') { // options Object.keys(type).forEach((key) => { parameter[key] = type[key]; }); } + // convert 2D Array into fields [] of data objects for (let i = 0; i < data.length; i += 1) { - data[i].unshift(''); // adds empty name for each data node - // eslint-disable-next-line no-param-reassign - [data[i][2], data[i][1]] = [data[i][1], data[i][2]]; // swaps values + const field = { type: data[i][1], value: data[i][0] }; + if (typeof data[i][2] === 'object') { + Object.keys(data[i][2]).forEach((key) => { // options + field[key] = data[i][2][key]; + }); + } + parameter.fields.push(field); } } else { - parameter.value = data; parameter.type = type; + parameter.value = data; if (!type) { iPgmDeprecate('defaulting parameter type to 1024a has been deprecated. You should specify a type instead.'); parameter.type = '1024a'; } - if (typeof options === 'object') { + if (typeof options === 'object') { // options Object.keys(options).forEach((key) => { parameter[key] = options[key]; }); From 5d2ee265906996f2be012d11005349595a679f0a Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Tue, 24 Mar 2020 19:13:53 -0500 Subject: [PATCH 09/11] fixup! test: Update ProgramCallUnit with addParam changes --- test/unit/ProgamCallUnit.js | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/unit/ProgamCallUnit.js b/test/unit/ProgamCallUnit.js index 0c2dba14..50e9c4c3 100644 --- a/test/unit/ProgamCallUnit.js +++ b/test/unit/ProgamCallUnit.js @@ -25,20 +25,20 @@ const { ProgramCall } = require('../../lib/itoolkit'); // now in this format // [name, type, value, options] const outBuf = [ - ['', '10i0', 0], - ['', '10i0', 0], - ['', '36h', ''], - ['', '10A', ''], - ['', '1A', ''], - ['', '1A', ''], - ['', '10i0', 0], - ['', '10i0', 0], + { type: '10i0', value: 0 }, + { type: '10i0', value: 0 }, + { type: '36h', value: '' }, + { type: '10A', value: '' }, + { type: '1A', value: '' }, + { type: '1A', value: '' }, + { type: '10i0', value: 0 }, + { type: '10i0', value: 0 }, ]; const errno = [ - ['', '10i0', 0], - ['', '10i0', 0, { setlen: 'rec2' }], - ['', '7A', ''], - ['', '1A', ''], + { type: '10i0', value: 0 }, + { type: '10i0', value: 0, setlen: 'rec2' }, + { type: '7A', value: '' }, + { type: '1A', value: '' }, ]; describe('ProgramCall Class Unit Tests', () => { @@ -73,7 +73,7 @@ describe('ProgramCall Class Unit Tests', () => { error: 'fast', }); - pgm.addParam({ value: outBuf, io: 'out', type: 'ds' }); + pgm.addParam({ fields: outBuf, io: 'out', type: 'ds' }); let expectedXML = '' + '0' @@ -120,7 +120,7 @@ describe('ProgramCall Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); pgm.addParam({ - value: errno, type: 'ds', io: 'both', len: 'rec2', + fields: errno, type: 'ds', io: 'both', len: 'rec2', }); expectedXML = '' @@ -152,12 +152,12 @@ describe('ProgramCall Class Unit Tests', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); const params = [ - ['', '3s0', 0], - ['', '7s0', 0, { name: 'ds_fld2' }], + { type: '3s0', value: 0 }, + { type: '7s0', value: 0, name: 'ds_fld2' }, ]; pgm.addParam({ - value: params, type: 'ds', name: 'inds', by: 'val', + fields: params, type: 'ds', name: 'inds', by: 'val', }); pgm.addReturn('', '2A', { name: 'output' }); @@ -182,12 +182,12 @@ describe('ProgramCall Class Unit Tests', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); const params = [ - ['', '3s0', 0], - ['', '7s0', 0, { name: 'ds_fld2' }], + { type: '3s0', value: 0 }, + { type: '7s0', value: 0, name: 'ds_fld2' }, ]; pgm.addParam({ - value: params, type: 'ds', name: 'inds', by: 'val', io: 'both', + fields: params, type: 'ds', name: 'inds', by: 'val', io: 'both', }); pgm.addReturn('', '2A', { name: 'output' }); From 03058e2742f62251cb5b5603992510589c418b35 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Wed, 25 Mar 2020 12:51:32 -0500 Subject: [PATCH 10/11] fixup! fixup! test: Update ProgramCallUnit with addParam changes --- test/unit/ProgamCallUnit.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/unit/ProgamCallUnit.js b/test/unit/ProgamCallUnit.js index 50e9c4c3..f881a6f9 100644 --- a/test/unit/ProgamCallUnit.js +++ b/test/unit/ProgamCallUnit.js @@ -22,8 +22,6 @@ const { expect } = require('chai'); const { ProgramCall } = require('../../lib/itoolkit'); -// now in this format -// [name, type, value, options] const outBuf = [ { type: '10i0', value: 0 }, { type: '10i0', value: 0 }, @@ -73,7 +71,7 @@ describe('ProgramCall Class Unit Tests', () => { error: 'fast', }); - pgm.addParam({ fields: outBuf, io: 'out', type: 'ds' }); + pgm.addParam({ type: 'ds', io: 'out', fields: outBuf }); let expectedXML = '' + '0' @@ -120,7 +118,7 @@ describe('ProgramCall Class Unit Tests', () => { expect(pgm.toXML()).to.equal(expectedXML); pgm.addParam({ - fields: errno, type: 'ds', io: 'both', len: 'rec2', + type: 'ds', io: 'both', len: 'rec2', fields: errno, }); expectedXML = '' @@ -157,7 +155,7 @@ describe('ProgramCall Class Unit Tests', () => { ]; pgm.addParam({ - fields: params, type: 'ds', name: 'inds', by: 'val', + name: 'inds', type: 'ds', by: 'val', fields: params, }); pgm.addReturn('', '2A', { name: 'output' }); @@ -187,7 +185,7 @@ describe('ProgramCall Class Unit Tests', () => { ]; pgm.addParam({ - fields: params, type: 'ds', name: 'inds', by: 'val', io: 'both', + name: 'inds', type: 'ds', by: 'val', io: 'both', fields: params, }); pgm.addReturn('', '2A', { name: 'output' }); From af333b9745d2bbc725720a0e38c83c2dd65e9f00 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Wed, 25 Mar 2020 13:04:44 -0500 Subject: [PATCH 11/11] fixup! refactor: ProgramCall.addParam to accept an object --- lib/ProgramCall.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index 79dfe82f..fb726d7f 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -43,6 +43,7 @@ class ProgramCall { if (data.type === 'ds') { this.xml += ' options + if (data.name) { this.xml += ` name='${data.name}'`; } if (data.dim) { this.xml += ` dim='${data.dim}'`; } if (data.dou) { this.xml += ` dou='${data.dou}'`; } if (data.len) { this.xml += ` len='${data.len}'`; } @@ -81,7 +82,7 @@ class ProgramCall { } this.xml += '