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

issue #9: ISailplaneAPIGatewayProxyEvent Interface #8

Merged
merged 8 commits into from
Jul 26, 2019
Merged

issue #9: ISailplaneAPIGatewayProxyEvent Interface #8

merged 8 commits into from
Jul 26, 2019

Conversation

voodooGQ
Copy link
Contributor

Addresses a simple issue when utilizing AWS.APIGatewayProxyEvent items where the body attribute is considered incorrect by tsconfig. The AWS.APIGatewayProxyEvent has this cast a string, however the middleware converts it to an object.

Still getting up to speed on Typescript, so if there's a better way to handle this I'm all ears.

Very large package-lock change. Don't know if we want to do that as a separate PR or not.

@voodooGQ voodooGQ marked this pull request as ready for review July 18, 2019 16:32
@voodooGQ
Copy link
Contributor Author

#9

@voodooGQ voodooGQ changed the title ISailplaneAPIGatewayProxyEvent Interface issue #9: ISailplaneAPIGatewayProxyEvent Interface Jul 18, 2019
@troyready
Copy link
Contributor

I think the package-lock changes should be dropped from this (since no dependencies are being changed).

@voodooGQ
Copy link
Contributor Author

@troyready Sounds good, I'll push up that adjustment

Copy link
Collaborator

@kernwig kernwig left a comment

Choose a reason for hiding this comment

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

If we're going to do this, here's my recommended changes.

* Casted interface for APIGatewayProxyEvents converted through the middleware
*
* @typedef {Interface}
* @property {any} body The cast JSON -> object body element
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need these tags - they are useless. Typescript removes the need for some JsDoc that violates the DRY principle, and body is being document by its own JsDoc.

/**
* Cast JSON -> object body element
* @property body
* @type {any}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove repetitive JsDoc.

Let's actually describe what this property is: HTTP Request body, parsed from a JSON string into an object.

* @typedef {Interface}
* @property {any} body The cast JSON -> object body element
*/
export interface ISailplaneAPIGatewayProxyEvent extends APIGatewayProxyEvent {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless you work at Microsoft, let's not use Hungarian notation. 😜

I'm tempted to call this APIGatewayProxyEvent still. Since LambdaUtils is used as import * as LambdaUtils from "@sailplane/lambda-utils", it would become LambdaUtils.APIGatewayProxyEvent to distinguish it.

In order to do this declaration, you add as AWS_APIGatewayProxyEvent to the import, and then use that name here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the linter rules I have states to keep Interface prefixed with an "I". Is that not the case in normal practice? I'm hoping not because I'd love to turn that rule off

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've never seen that rule. Turn it off.
palantir/tslint#1520

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 the rule I'm referring to :)

* @type {any}
*/
body: any;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since LambdaUtils also de-nulls queryStringParameters and pathParameters, can do those too:

    pathParameters: { [name: string]: string };
    queryStringParameters: { [name: string]: string };

* HTTP Request body, parsed from a JSON string into an object.
* @property body
*/
body: any;
Copy link
Collaborator

Choose a reason for hiding this comment

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

In speaking with a colleague, I remember that this transformation only happens when the received body has JSON content. So the body can be left untouched, as string | null. Since any includes string, please just add the | null which will be true if no body was received.


/**
* HTTP URL query string parameters, parsed from a JSON string into an object
* @property pathParameters
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please explain to me the value of this tag. Just seems like an opportunity to be out of sync with the actual code. (Which it is indeed right here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you want me to explain on this one. It's a standard jsdoc element. If you'd prefer it removed I'll happily do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

From that page "This tag is intended for simple collections of static properties". See the example. This is not what that tag is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, and already addressed

pathParameters: { [name: string]: string };

/**
* HTTP URL query string parameters, parsed from a JSON string into an object
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry... just a pair of mistakes here in the descriptions of both of these two new properties. They are not parsed from JSON strings. What LambdaUtils does is guarantee that they are defined. So they will be an empty object rather than null if there are no path parameters or query string. Maybe the part after the comma on both of these would read "always defined, never null."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry just seeing this, I'll go in and make that change quick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kernwig kernwig merged commit 283e09e into rackspace:master Jul 26, 2019
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.

3 participants