Skip to content

Refactor Connection.js, transports, and Toolkit.js #42

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

Merged
merged 6 commits into from
Mar 11, 2019
Merged

Refactor Connection.js, transports, and Toolkit.js #42

merged 6 commits into from
Mar 11, 2019

Conversation

abmusse
Copy link
Member

@abmusse abmusse commented Mar 7, 2019

Connection class:

Constructor now supports passing a single object for configuration. see issue #25

Old signature with positional arguments are still supported.

reworked Connection.run() method:

run function invokes the transport function and passes:

  • config: the object with configuration details
  • xmlInput: the input xml document
  • done: function to be invoked by the transport

run function now provides error first callback by default this resolved issue #2.

This can be configured through returnError property.

removed setTimeout() and timeout property since we no longer have sync mode, see issue #32

renamed internal variables away from I_* prefix that was used before.

No longer set defaults for transport options simply pass the options object to the transport.

Transports now deals with setting defaults and validate required parameters are OK.

renamed getConnection() to getTransportOptions()

Transports

  • updated to interface to accept config, xmlInput, done

  • In istoredp.js moved to use iPLUGR512K procedure which returns a result set.

  • transports were moved lib/transports/ directory

Toolkit.js

Updated Toolkit methods to return error first callbacks

@abmusse abmusse requested review from kadler, markdirish and dmabupt March 7, 2019 22:45
@kadler
Copy link
Member

kadler commented Mar 8, 2019

Why was a new PR opened instead of updating the existing one?

@abmusse
Copy link
Member Author

abmusse commented Mar 8, 2019

The original PR contained more commits, updates to the tests and other files.

I decided to exclude those commits from this PR and have those changes be in a separate PR next.

Also these changes were added to separate branch therefore could not use the same PR.

If its easier I can push these commits over to reworkConnection branch and reopen the previous PR.

options.username = username;
options.password = password;
options.transport = 'idb';
options.returnError = false;
Copy link
Member

Choose a reason for hiding this comment

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

could do something like:

options = {
  database: optionsOrDb,
  username: username,
  ...
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Will patch to be

      options = {
        returnError: false,
        transport: 'idb',
        transportOptions: {
          database: optionsOrDb,
          username,
          password
        }
      }

options = {};
options.database = optionsOrDb;
options.username = username;
options.password = password;
Copy link
Member

Choose a reason for hiding this comment

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

are database, username, and password not transport options?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes will add those properties to options.transportOptions sub object.

delete options.transport;
delete options.returnError;

this.transportOptions = { ...options };
Copy link
Member

Choose a reason for hiding this comment

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

Why is the user not passing in a transportOptions sub object?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking the user would pass in the object in the format like:

{
 returnError,
 transport,
 username,
 password,
....
}

We could design it for the user to pass in the object like:

{
   returnError,
   transport,
   transportOptions: { username, password, ....}
}

Copy link
Member

Choose a reason for hiding this comment

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

I think that's best. Any transport-specific options are in the transportOptions key and you just pass it through to the transport. Then there's no confusion about what key is used for what.

@abmusse
Copy link
Member Author

abmusse commented Mar 9, 2019

@kadler pushed up an update d041d99 that uses:

options = {
   returnError,
   transport,
   transportOptions: { username, password, ....}
}

Should resolve the above suggestions

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.

LGTM

abmusse added 5 commits March 11, 2019 13:32
Allow Connection.js Constuctor to accept a single object see #25
Allow Connection.run() function to return error as first param of callback see #2

Establish one code path in Connection Constructor
- when pre v1.0 signature is used create an options object
- add properties to this options object
- this mimics the current v1.0 way of passing a signle object
- that way constructor follows on code path

Options object contain sub object transportOptions
- This contains properties such as databse, username, etc
- This sub object is passed to the transport

Rename variables away from I_* prefix
Rename getConnection() -> getTransportOptions()
Rename cmd -> commandList

Moved verbose to be a property of Connection
- verbose is added to transportOptions during run()
- this is because verbose can be adjusted with debug()
- add print of xmlOutput also when in verbose mode
- We no longer support sync mode which had an option to set timeout
Update transports interface to accept config, xmlInput, done

idb transport

Use iPLUGR512k variant instead of iPLUG512k to iterate over a result set

Ensure conn and stmt are always cleaned up properly
- even during error states the stmt and conn objects are now cleaned
- add function clean() to avoid duplication
- this commit should help resolve issue #17

rest transport

Validate required: database, username, password

Enforce output buffer to be set to the max
- before default was only set now output buffer is always set to the max

Small fixes add mising semicolons, remove some comments, etc
- moved irest.js
- moved istoredp.js
- Now all toolkit methods will have error first callbacks
@abmusse
Copy link
Member Author

abmusse commented Mar 11, 2019

LGTM

I'm going to clean up a bit and squash incremental commits together to be more stream-lined

@abmusse
Copy link
Member Author

abmusse commented Mar 11, 2019

Cleaned up and Squashed:

image

Into:

image

Going merge PR into v1.0-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants