From 6a6a458b9770ad0320be5dd7672dd4266c58dc1e Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Wed, 20 Jan 2021 13:05:47 -0600 Subject: [PATCH 1/3] feat: Add data type wrappers --- lib/Types.js | 190 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/itoolkit.js | 3 + 2 files changed, 193 insertions(+) create mode 100644 lib/Types.js diff --git a/lib/Types.js b/lib/Types.js new file mode 100644 index 00000000..6b371302 --- /dev/null +++ b/lib/Types.js @@ -0,0 +1,190 @@ +// Copyright (c) International Business Machines Corp. 2019 + +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// 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. + +/* + * From XMLSERVICEQUICK reference + * http://yips.idevcloud.com/wiki/index.php/XMLService/XMLSERVICEQuick + * + * data - data value name (tag) + * values - value, + * type + * 3i0 int8/byte D myint8 3i 0 + * 5i0 int16/short D myint16 5i 0 + * 10i0 int32/int D myint32 10i 0 + * 20i0 int64/int64 D myint64 20i 0 + * 3u0 uint8/ubyte D myint8 3u 0 + * 5u0 uint16/ushort D myint16 5u 0 + * 10u0 uint32/uint D myint32 10u 0 + * 20u0 uint64/uint64 D myint64 20u 0 + * 32a char D mychar 32a + * 32a {varying2} varchar D mychar 32a varying + * 32a {varying4} varchar4 D mychar 32a varying(4) + * 12p2 packed D mydec 12p 2 + * 12s2 zoned D myzone 12s 2 + * 4f2 float D myfloat 4f + * 8f4 real/double D myfloat 8f + * 3b binary D mybin (any) +*/ + +/** + * @param {number} length - The number of binary characters. + * @returns {string} - The binary data type format expected by xml service. + */ + +function Binary(length) { + return `${length}b`; +} + +/** + * @param {number} length - The number of characters within the varchar. + * @returns {string} - The character data type format expected by xml service. + */ +function Char(length) { + return `${length}a`; +} + +/** + * @returns {string} - The double data type format expected by xml service. + */ +function Double() { + return '8F4'; +} + +/** + * @returns {string} - The float data type format expected by xml service. + */ +function Float() { + return '4F2'; +} + +/** + * @param {number} length - The number of characters. + * @returns {string} - The long varchar data type format expected by + * xml service. + */ +function LongVarchar(length) { + return { type: `${length}a`, varying: '4' }; +} + +/** + * @param {number} totalDigits -The number of integer digits. + * @param {number} decimalDigits - The number of decimal digits. + * @returns {string} - The packed data type format expected by xml service. + */ +function Packed(totalDigits, decimalDigits) { + return `${totalDigits}p${decimalDigits}`; +} + +/** + * @returns {string} The signed big int (int64) data type format expected by + * xml service. + */ +function SignedBigInt() { + return '20i0'; +} + +/** + * @returns {string} The signed byte (int8) data type foramt expected by + * xml service. + */ +function SignedByte() { + return '3i0'; +} + +/** + * @returns {string} The signed int (int32) data type format expected by xml service. + */ +function SignedInt() { + return '10i0'; +} + +/** + * @returns {string} The signed short (int16) data type format expected by + * xml service. + */ +function SignedShort() { + return '5i0'; +} + +/** + * @returns {string} The unsigned big int (int64) data type format expected by + * xml service. + */ +function UnsignedBigInt() { + return '20u0'; +} + +/** + * @returns {string} The unsigned byte (int8) data type foramt expected by + * xml service. + */ +function UnsignedByte() { + return '3u0'; +} + +/** + * @returns {string} The unsigned int (int32) data type format expected by + * xml service. + */ +function UnsignedInt() { + return '10u0'; +} + + +/** + * @returns {string} The signed short (int16) data type format expected by + * xml service. + */ +function UnsignedShort() { + return '5u0'; +} + +/** + * @param {number} length - The number of characters. + * @returns {string} - The varchar data type format expected by xml service. + */ +function Varchar(length) { + return { type: `${length}a`, varying: '2' }; +} + +/** + * @param {number} totalDigits - The number of integer digits. + * @param {number} decimalDigits - The number of decimal digits. + * @returns {string} - The zoned data type format expected by xml service. + */ +function Zoned(totalDigits, decimalDigits) { + return `${totalDigits}s${decimalDigits}`; +} + +module.exports = { + Binary, + Char, + Double, + Float, + LongVarchar, + Packed, + SignedBigInt, + SignedByte, + SignedInt, + SignedShort, + UnsignedBigInt, + UnsignedByte, + UnsignedInt, + UnsignedShort, + Varchar, + Zoned, +}; diff --git a/lib/itoolkit.js b/lib/itoolkit.js index c1b9bf27..863c1ad5 100644 --- a/lib/itoolkit.js +++ b/lib/itoolkit.js @@ -39,10 +39,13 @@ const { xmlToJson, } = require('./Deprecated'); +const Types = require('./Types'); + module.exports = { ProgramCall, CommandCall, Connection, + ...Types, xmlToJson, // deprecated exports below, replaced by functionality above iCmd, From 1869ad4a54635f13218b588d18689b1014eabec2 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Wed, 20 Jan 2021 18:50:42 -0600 Subject: [PATCH 2/3] fixup! feat: Add data type wrappers --- lib/Types.js | 95 ++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/lib/Types.js b/lib/Types.js index 6b371302..fdcfcb9e 100644 --- a/lib/Types.js +++ b/lib/Types.js @@ -46,7 +46,7 @@ */ function Binary(length) { - return `${length}b`; + return { type: `${length}b` }; } /** @@ -54,39 +54,56 @@ function Binary(length) { * @returns {string} - The character data type format expected by xml service. */ function Char(length) { - return `${length}a`; + return { type: `${length}a` }; +} + +/** + * @param {number} length - The number of characters. + * @returns {string} - The long varchar data type format expected by + * xml service. + */ +function LongVarchar(length) { + return { type: `${length}a`, varying: '4' }; +} + +/** + * @param {number} length - The number of characters. + * @returns {string} - The varchar data type format expected by xml service. + */ +function Varchar(length) { + return { type: `${length}a`, varying: '2' }; } /** * @returns {string} - The double data type format expected by xml service. */ function Double() { - return '8F4'; + return { type: '8f4' }; } /** * @returns {string} - The float data type format expected by xml service. */ function Float() { - return '4F2'; + return { type: '4f2' }; } /** - * @param {number} length - The number of characters. - * @returns {string} - The long varchar data type format expected by - * xml service. + * @param {number} totalDigits -The number of integer digits. + * @param {number} decimalDigits - The number of decimal digits. + * @returns {string} - The packed data type format expected by xml service. */ -function LongVarchar(length) { - return { type: `${length}a`, varying: '4' }; +function PackedDecimal(totalDigits, decimalDigits) { + return { type: `${totalDigits}p${decimalDigits}` }; } /** - * @param {number} totalDigits -The number of integer digits. + * @param {number} totalDigits - The number of integer digits. * @param {number} decimalDigits - The number of decimal digits. - * @returns {string} - The packed data type format expected by xml service. + * @returns {string} - The zoned data type format expected by xml service. */ -function Packed(totalDigits, decimalDigits) { - return `${totalDigits}p${decimalDigits}`; +function ZonedDecimal(totalDigits, decimalDigits) { + return { type: `${totalDigits}s${decimalDigits}` }; } /** @@ -94,7 +111,7 @@ function Packed(totalDigits, decimalDigits) { * xml service. */ function SignedBigInt() { - return '20i0'; + return { type: '20i0' }; } /** @@ -102,14 +119,14 @@ function SignedBigInt() { * xml service. */ function SignedByte() { - return '3i0'; + return { type: '3i0' }; } /** * @returns {string} The signed int (int32) data type format expected by xml service. */ function SignedInt() { - return '10i0'; + return { type: '10i0' }; } /** @@ -117,15 +134,21 @@ function SignedInt() { * xml service. */ function SignedShort() { - return '5i0'; + return { type: '5i0' }; } +// aliases for signed types +const BigInt = SignedBigInt; +const Byte = SignedByte; +const Int = SignedInt; +const Short = SignedShort; + /** * @returns {string} The unsigned big int (int64) data type format expected by * xml service. */ function UnsignedBigInt() { - return '20u0'; + return { type: '20u0' }; } /** @@ -133,7 +156,7 @@ function UnsignedBigInt() { * xml service. */ function UnsignedByte() { - return '3u0'; + return { type: '3u0' }; } /** @@ -141,50 +164,36 @@ function UnsignedByte() { * xml service. */ function UnsignedInt() { - return '10u0'; + return { type: '10u0' }; } - /** * @returns {string} The signed short (int16) data type format expected by * xml service. */ function UnsignedShort() { - return '5u0'; -} - -/** - * @param {number} length - The number of characters. - * @returns {string} - The varchar data type format expected by xml service. - */ -function Varchar(length) { - return { type: `${length}a`, varying: '2' }; -} - -/** - * @param {number} totalDigits - The number of integer digits. - * @param {number} decimalDigits - The number of decimal digits. - * @returns {string} - The zoned data type format expected by xml service. - */ -function Zoned(totalDigits, decimalDigits) { - return `${totalDigits}s${decimalDigits}`; + return { type: '5u0' }; } module.exports = { Binary, Char, + LongVarchar, + Varchar, Double, Float, - LongVarchar, - Packed, + PackedDecimal, + ZonedDecimal, SignedBigInt, + BigInt, SignedByte, + Byte, SignedInt, + Int, SignedShort, + Short, UnsignedBigInt, UnsignedByte, UnsignedInt, UnsignedShort, - Varchar, - Zoned, }; From 2a5c6c5caa540b5876225d4f81903c923d2461b3 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Tue, 23 Feb 2021 09:16:40 -0600 Subject: [PATCH 3/3] fixup! fixup! feat: Add data type wrappers --- lib/Types.js | 72 ++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/Types.js b/lib/Types.js index fdcfcb9e..3e48ff86 100644 --- a/lib/Types.js +++ b/lib/Types.js @@ -18,31 +18,31 @@ /* * From XMLSERVICEQUICK reference * http://yips.idevcloud.com/wiki/index.php/XMLService/XMLSERVICEQuick - * - * data - data value name (tag) - * values - value, - * type - * 3i0 int8/byte D myint8 3i 0 - * 5i0 int16/short D myint16 5i 0 - * 10i0 int32/int D myint32 10i 0 - * 20i0 int64/int64 D myint64 20i 0 - * 3u0 uint8/ubyte D myint8 3u 0 - * 5u0 uint16/ushort D myint16 5u 0 - * 10u0 uint32/uint D myint32 10u 0 - * 20u0 uint64/uint64 D myint64 20u 0 - * 32a char D mychar 32a - * 32a {varying2} varchar D mychar 32a varying - * 32a {varying4} varchar4 D mychar 32a varying(4) - * 12p2 packed D mydec 12p 2 - * 12s2 zoned D myzone 12s 2 - * 4f2 float D myfloat 4f - * 8f4 real/double D myfloat 8f - * 3b binary D mybin (any) + * ------------------------------------------------------------------- + * | xmlservice | C/SQL | Fixed-format RPG | + * ------------------------------------------------------------------- + * | 3i0 | int8/byte | D myint8 3i 0 | + * | 5i0 | int16/short | D myint16 5i 0 | + * | 10i0 | int32/int | D myint32 10i 0 | + * | 20i0 | int64/int64 | D myint64 20i 0 | + * | 3u0 | uint8/ubyte | D myint8 3u 0 | + * | 5u0 | uint16/ushort | D myint16 5u 0 | + * | 10u0 | uint32/uint | D myint32 10u 0 | + * | 20u0 | uint64/uint64 | D myint64 20u 0 | + * | 32a | char | D mychar 32a | + * | 32a (varying=2) | varchar | D mychar 32a varying | + * | 32a (varying=4) | varchar4 | D mychar 32a varying(4) | + * | 12p2 | packed | D mydec 12p 2 | + * | 12s2 | zoned | D myzone 12s 2 | + * | 4f2 | float | D myfloat 4f | + * | 8f4 | real/double | D myfloat 8f | + * | 3b | binary | D mybin (any) | + * ------------------------------------------------------------------- */ /** * @param {number} length - The number of binary characters. - * @returns {string} - The binary data type format expected by xml service. + * @returns {object} - The binary data type format expected by xml service. */ function Binary(length) { @@ -51,7 +51,7 @@ function Binary(length) { /** * @param {number} length - The number of characters within the varchar. - * @returns {string} - The character data type format expected by xml service. + * @returns {object} - The character data type format expected by xml service. */ function Char(length) { return { type: `${length}a` }; @@ -59,7 +59,7 @@ function Char(length) { /** * @param {number} length - The number of characters. - * @returns {string} - The long varchar data type format expected by + * @returns {object} - The long varchar data type format expected by * xml service. */ function LongVarchar(length) { @@ -68,21 +68,21 @@ function LongVarchar(length) { /** * @param {number} length - The number of characters. - * @returns {string} - The varchar data type format expected by xml service. + * @returns {object} - The varchar data type format expected by xml service. */ function Varchar(length) { return { type: `${length}a`, varying: '2' }; } /** - * @returns {string} - The double data type format expected by xml service. + * @returns {object} - The double data type format expected by xml service. */ function Double() { return { type: '8f4' }; } /** - * @returns {string} - The float data type format expected by xml service. + * @returns {object} - The float data type format expected by xml service. */ function Float() { return { type: '4f2' }; @@ -91,7 +91,7 @@ function Float() { /** * @param {number} totalDigits -The number of integer digits. * @param {number} decimalDigits - The number of decimal digits. - * @returns {string} - The packed data type format expected by xml service. + * @returns {object} - The packed data type format expected by xml service. */ function PackedDecimal(totalDigits, decimalDigits) { return { type: `${totalDigits}p${decimalDigits}` }; @@ -100,14 +100,14 @@ function PackedDecimal(totalDigits, decimalDigits) { /** * @param {number} totalDigits - The number of integer digits. * @param {number} decimalDigits - The number of decimal digits. - * @returns {string} - The zoned data type format expected by xml service. + * @returns {object} - The zoned data type format expected by xml service. */ function ZonedDecimal(totalDigits, decimalDigits) { return { type: `${totalDigits}s${decimalDigits}` }; } /** - * @returns {string} The signed big int (int64) data type format expected by + * @returns {object} The signed big int (int64) data type format expected by * xml service. */ function SignedBigInt() { @@ -115,7 +115,7 @@ function SignedBigInt() { } /** - * @returns {string} The signed byte (int8) data type foramt expected by + * @returns {object} The signed byte (int8) data type foramt expected by * xml service. */ function SignedByte() { @@ -123,14 +123,14 @@ function SignedByte() { } /** - * @returns {string} The signed int (int32) data type format expected by xml service. + * @returns {object} The signed int (int32) data type format expected by xml service. */ function SignedInt() { return { type: '10i0' }; } /** - * @returns {string} The signed short (int16) data type format expected by + * @returns {object} The signed short (int16) data type format expected by * xml service. */ function SignedShort() { @@ -144,7 +144,7 @@ const Int = SignedInt; const Short = SignedShort; /** - * @returns {string} The unsigned big int (int64) data type format expected by + * @returns {object} The unsigned big int (int64) data type format expected by * xml service. */ function UnsignedBigInt() { @@ -152,7 +152,7 @@ function UnsignedBigInt() { } /** - * @returns {string} The unsigned byte (int8) data type foramt expected by + * @returns {object} The unsigned byte (int8) data type foramt expected by * xml service. */ function UnsignedByte() { @@ -160,7 +160,7 @@ function UnsignedByte() { } /** - * @returns {string} The unsigned int (int32) data type format expected by + * @returns {object} The unsigned int (int32) data type format expected by * xml service. */ function UnsignedInt() { @@ -168,7 +168,7 @@ function UnsignedInt() { } /** - * @returns {string} The signed short (int16) data type format expected by + * @returns {object} - The signed short (int16) data type format expected by * xml service. */ function UnsignedShort() {