Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 190 additions & 0 deletions lib/Types.js
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 3i0 int8/byte D myint8 3i 0
* xmlservice C/SQL Fixed-format RPG
* 3i0 int8/byte D myint8 3i 0

Maybe add a header?

I think it would also be nicer to space out the columns a bit and maybe put in some separator bars. The RPG example is a bit close to the "C" example.

* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 32a char D mychar 32a
* 32a char[32] D mychar 32a

* 32a {varying2} varchar D mychar 32a varying
* 32a {varying4} varchar4 D mychar 32a varying(4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 32a {varying2} varchar D mychar 32a varying
* 32a {varying4} varchar4 D mychar 32a varying(4)
* 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.
*/

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it's case sensitive, but for consistency I think we should use lowercase f in the types returned here.

}

/**
* @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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems more clear as PackedDecimal. Same goes for Zoned later.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these @returns be adjusted? They don't actually return a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup these need to updated to return objects instead.

* 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,
};
3 changes: 3 additions & 0 deletions lib/itoolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down