Skip to content

feat: Add data type wrappers - #321

Open
abmusse wants to merge 3 commits into
masterfrom
add-data-type-wrappers
Open

feat: Add data type wrappers#321
abmusse wants to merge 3 commits into
masterfrom
add-data-type-wrappers

Conversation

@abmusse

Copy link
Copy Markdown
Member

Resolves#75
Resolves#77

@kadlerkadler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks OK to me. I'd probably group them by type instead of alphabetically. Might want to add aliases to the Signed* functions without the "Signed" (ie. Int, BigInt, etc).

Does the spread operator work when the value is a string instead of an object? If not, I think the functions should all return objects.

Comment threadlib/Types.js Outdated
Comment on lines +64 to +71
return '8F4';
}

/**
* @returns {string} - The float data type format expected by xml service.
*/
function Float() {
return '4F2';

Copy link
Copy Markdown
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.

Comment threadlib/Types.js Outdated
* @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
Copy Markdown
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.

@abmusse
abmusse marked this pull request as ready for review January 20, 2021 22:22
@abmusseabmusse added this to the Version 1.1 milestone Jan 20, 2021
@abmusse

Copy link
Copy Markdown
MemberAuthor

Looks OK to me. I'd probably group them by type instead of alphabetically. Might want to add aliases to the Signed* functions without the "Signed" (ie. Int, BigInt, etc).

Does the spread operator work when the value is a string instead of an object? If not, I think the functions should all return objects.

Spread operator does work on strings but not in the way we want. It essentially will split each character in the string with a space:

functionSignedBigInt(){return'20i0';}console.log('Signed Big Int:', ...SignedBigInt())// Signed Big Int: 2 0 i 0

I agree we should return an object with type key set to the return value.

@abmusse

Copy link
Copy Markdown
MemberAuthor

I think we also should we add checks to enforce length parameter was passed for

  • Char
  • Varchar
  • LongVarchar

As is if no length is provided to these functions we end up something like this:

> const { Varchar } = require('itoolkit');
> console.log({...itoolkit.Varchar()})
{ type: 'undefineda', varying: '2' }

Check could be something like ...

functionVarchar(length){if(!length){throwTypeError('Must provide valid length for Varchar');}return{type: `${length}a`,varying: '2'};}
> const { Varchar } = require('itoolkit');
> console.log({...itoolkit.Varchar()})
Uncaught TypeError: Must provide length for Varchar

Alternatively we could have a default length or no-op when no length is passed.

@github-actions

Copy link
Copy Markdown

👋 Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

@abmusseabmusse added keep-open Exempts stale action from auto closing the issue/pr. and removed stale labels Feb 22, 2021
Comment threadlib/Types.js Outdated
* data - data value name (tag)
* values - value,
* type
* 3i0 int8/byte D myint8 3i 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
*3i0int8/byteDmyint83i0
*xmlserviceC/SQLFixed-formatRPG
*3i0int8/byteDmyint83i0

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.

Comment threadlib/Types.js Outdated
Comment on lines +34 to +35
* 32a {varying2} varchar D mychar 32a varying
* 32a {varying4} varchar4 D mychar 32a varying(4)

Copy link
Copy Markdown
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}varcharDmychar32avarying
*32a{varying4}varchar4Dmychar32avarying(4)
*32a(varying=2)varcharDmychar32avarying
*32a(varying=4)varchar4Dmychar32avarying(4)

Comment threadlib/Types.js Outdated
* 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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
*32acharDmychar32a
*32achar[32]Dmychar32a

Comment threadlib/Types.js Outdated
const Short = SignedShort;

/**
* @returns {string} The unsigned big int (int64) data type format expected by

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

@abmusse
abmusse requested a review from kadlerFebruary 23, 2021 20:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep-openExempts stale action from auto closing the issue/pr.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iPgm parameters: Make declarations for parameter types easier to use

2 participants

@abmusse@kadler