Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add data type wrappers #321

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

abmusse
Copy link
Member

@abmusse abmusse commented Jan 20, 2021

Resolves #75
Resolves #77

Copy link
Member

@kadler kadler left a comment

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.

lib/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
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.

lib/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
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
@abmusse abmusse added this to the Version 1.1 milestone Jan 20, 2021
@abmusse
Copy link
Member Author

abmusse commented Jan 21, 2021

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:

function SignedBigInt() {
  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
Member Author

abmusse commented Jan 21, 2021

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 ...

function Varchar(length) {
  if (!length) { throw TypeError('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

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

@github-actions github-actions bot added the stale label Feb 21, 2021
@abmusse abmusse added keep-open Exempts stale action from auto closing the issue/pr. and removed stale labels Feb 22, 2021
lib/Types.js Outdated
* 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.

lib/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
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)

lib/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
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

lib/Types.js Outdated
const Short = SignedShort;

/**
* @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.

@abmusse abmusse requested a review from kadler February 23, 2021 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-open Exempts 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