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

refactor: change all websocket method parameters to lower camel case #941

Merged
merged 3 commits into from
Aug 26, 2019

Conversation

dpopp07
Copy link
Contributor

@dpopp07 dpopp07 commented Aug 23, 2019

Making all the changes to the WebSocket classes that I wanted to make for v5. The big one here is exposing only lowerCamelCase parameters to the user to match our style guide. The generator is also changing to generate camecase params for the generated code, so the hand-written code needs to be consistent.

Other things I did:

  • Wrote types for the Options objects passed into these classes
  • Removed all of the deprecated messages for the unsupported events
  • Removed support for the token parameter
  • Removed support for the customization_id parameter
  • Refactored the setAuthorizationHeaderToken method outside of the Stream classes so that they could share it - the exact same code was being used
  • Refactored how we process the query/payload parameters
  • Updated all of the parameters to match the type and description of what is currently in the API reference - there were some mismatches

@codecov-io
Copy link

codecov-io commented Aug 23, 2019

Codecov Report

Merging #941 into release-candidate-v5 will increase coverage by 0.15%.
The diff coverage is 93.02%.

Impacted file tree graph

@@                   Coverage Diff                    @@
##           release-candidate-v5     #941      +/-   ##
========================================================
+ Coverage                 54.38%   54.53%   +0.15%     
========================================================
  Files                        18       19       +1     
  Lines                      4505     4487      -18     
  Branches                    906      898       -8     
========================================================
- Hits                       2450     2447       -3     
+ Misses                     2053     2039      -14     
+ Partials                      2        1       -1
Impacted Files Coverage Δ
text-to-speech/v1.ts 46.34% <100%> (ø) ⬆️
lib/recognize-stream.ts 68.61% <100%> (+3.36%) ⬆️
lib/synthesize-stream.ts 82.97% <100%> (+0.22%) ⬆️
speech-to-text/v1.ts 31.81% <100%> (ø) ⬆️
lib/websocket-utils.ts 85% <85%> (ø)
test/resources/auth_helper.js 100% <0%> (+22.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de9fe5a...583178c. Read the comment docs.

Copy link

@mkistler mkistler left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

I just left one question about parameter descriptions.

* @param {Options} options
* @param {string} [url] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api')
* @param {OutgoingHttpHeaders} [headers] - Only works in Node.js, not in browsers. Allows for custom headers to be set, including an Authorization header (preventing the need for auth tokens)
* @param {boolean} [readableObjectMode] - Emit `result` objects instead of string Buffers for the `data` events. Does not affect input (which must be binary)

Choose a reason for hiding this comment

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

It looks like you removed the "options." from all the parameters that are passed in the "options" object. Was that intentional? It seems like it would be more correct to keep that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not intentional actually, I'll go back and fix that. Thanks for pointing it out 👍

const processedOptions = {};

// look for the camelcase version of each parameter - that is what we expose to the user
allowedParams.forEach(param => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do something like:

console.warn(`Unrecognized parameter `${param} in query string`);

I feel like it would really help users using the wrong key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, I'll try to add something there

Copy link
Contributor

@germanattanasio germanattanasio left a comment

Choose a reason for hiding this comment

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

The changes look good. Are you planning on mapping these changes to the speech-sdk?

@germanattanasio
Copy link
Contributor

germanattanasio commented Aug 26, 2019

Thanks for manually writing all the documentation for the query parameters. It takes a lot of time upfront but will help a lot of developers 👍

@dpopp07
Copy link
Contributor Author

dpopp07 commented Aug 26, 2019

Are you planning on mapping these changes to the speech-sdk?

I hadn't thought about it yet, but yes I think I should. I'll open an issue for that

* Also, add types for WebSocket Stream class constructor options

BREAKING CHANGE: All parameters have been converted to their lower camel case version.
BREAKING CHANGE: Support for the `token` parameter has been removed
BREAKING CHANGE: Support for the `customization_id` parameter has been removed
BREAKING CHANGE: Method `setAuthorizationHeaderToken` has been removed from the WebSocket Stream classes
@dpopp07 dpopp07 merged commit 3fa522c into release-candidate-v5 Aug 26, 2019
@dpopp07 dpopp07 deleted the websocket-method-types branch August 26, 2019 16:45
dpopp07 added a commit that referenced this pull request Sep 19, 2019
…941)

* add types for WebSocket Stream class constructor options
* warn user when a parameter is passed in that matches the service option but not the user option

BREAKING CHANGE: All parameters have been converted to their lower camel case version.
BREAKING CHANGE: Support for the `token` parameter has been removed
BREAKING CHANGE: Support for the `customization_id` parameter has been removed
BREAKING CHANGE: Method `setAuthorizationHeaderToken` has been removed from the WebSocket Stream classes
dpopp07 added a commit that referenced this pull request Oct 4, 2019
…941)

* add types for WebSocket Stream class constructor options
* warn user when a parameter is passed in that matches the service option but not the user option

BREAKING CHANGE: All parameters have been converted to their lower camel case version.
BREAKING CHANGE: Support for the `token` parameter has been removed
BREAKING CHANGE: Support for the `customization_id` parameter has been removed
BREAKING CHANGE: Method `setAuthorizationHeaderToken` has been removed from the WebSocket Stream classes
watson-github-bot pushed a commit that referenced this pull request Oct 4, 2019
# [5.0.0](v4.5.1...v5.0.0) (2019-10-04)

### Bug Fixes

* make RecognizeStream.readableObjectMode always return Boolean ([#943](#943)) ([a276df4](a276df4))

### Build System

* drop support for Node versions 6 and 8 ([3ea1fd7](3ea1fd7))

### Code Refactoring

* change all websocket method parameters to lower camel case ([#941](#941)) ([cb6711f](cb6711f))

### Features

* add support for new authenticators in all sdks and add new service features for major release ([#946](#946)) ([3acffc5](3acffc5))

### BREAKING CHANGES

* Passing individual credentials to the service constructor will no longer work. An Authenticator must be initialized and passed in. For more information, see the migration guide.
* All parameters have been converted to their lower camel case version.
* Support for the `token` parameter has been removed
* Support for the `customization_id` parameter has been removed
* Method `setAuthorizationHeaderToken` has been removed from the WebSocket Stream classes
* `RecognizeStream.readableObjectMode` will always be a Boolean value - before, it could have been `undefined`.
* This SDK may no longer work with applications running on Node 6 or 8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants