Skip to content

lib: rewrite in TypeScript #226

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 5 commits into from
Jun 29, 2020
Merged

lib: rewrite in TypeScript #226

merged 5 commits into from
Jun 29, 2020

Conversation

lance
Copy link
Member

@lance lance commented Jun 16, 2020

This is a major rewrite of the entire codebase into TypeScript. Where the code was overly complex, I have attempted to simplify things. A few things remain before it can land.

  • Modify linting rules to work better with TS project
  • Document the user facing API with ts-doc comments
  • Update the README.md with new examples
  • Update the example projects in /examples to work with the new API
  • Convert remainder of JavaScript tests to TypeScript
  • Normalize the use of constants
  • Add a test for custom headers (see Passing custom headers through to http.request() #223)
  • Add a test for binary data, encoded to base64
  • Review CloudEvent#extensions and how they are mapped to https://github.com/cloudevents/spec/blob/v1.0/json-format.md
  • Lowercase all CloudEvent property names per spec
  • Make HTTP transport mode an enum

Some notes about the changes...

  • The generated JS now is written to ./dist
  • The lib folder has been removed and everything under it was pulled up into src
  • The lib/bindings folder has been moved to src/transport

Fixes: #223
Fixes: #219
Fixes: #203
Fixes: #195

Signed-off-by: Lance Ball [email protected]

@lance lance added type/enhancement New feature or request typescript Issues related to TypeScript usage or implementation labels Jun 16, 2020
@lance lance requested a review from a team June 16, 2020 17:13
@lance lance self-assigned this Jun 16, 2020
@lance lance requested review from danbev, grant and fabiojose and removed request for a team June 16, 2020 17:13
@lance lance marked this pull request as draft June 16, 2020 17:16
@lholmquist
Copy link
Contributor

I noticed a _bundles directory getting created that is not .gitignored, should it be?

Copy link
Member

@grant grant left a comment

Choose a reason for hiding this comment

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

This is great!

I added a few comments, but this is definitely an improvement. I understand there can be a lot of feature creep with the PR, so I hope my comments don't try to nit at the things we can fix in the future.

@@ -0,0 +1 @@
export const enum Protocol { HTTPBinary, HTTPStructured, HTTP };
Copy link
Member

Choose a reason for hiding this comment

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

For small files like these, it might be worth it to inline it rather than have a new file.

For example, we can inline the contents into the index.ts file.

@lance
Copy link
Member Author

lance commented Jun 16, 2020

@lholmquist good catch! That's actually a bug on master. 🐛

This is a major rewrite of the entire codebase into TypeScript. Nearly
all tests have been retained except where behavior is significantly
different. Some highlights of these changes:

* lowercase all CloudEvent properties and fix base64 encoded data

Previously there was a format() function that would convert a CloudEvent
object into JSON with all of the properties lowercased. With this rewrite
a CloudEvent object can be converted to JSON simply with JSON.stringify().

However, in order to be compliant with the JSON representation outlined in
the spec here https://github.com/cloudevents/spec/blob/v1.0/json-format.md
all of the event properties must be all lowercase.

* lib(transport): make transport mode an Enum
* src: allow custom headers (#1)
* lib(exports): export explicitly versioned names where appropriate
* lib(cloudevent): modify ctor to accept extensions inline
* lib(cloudevent): make extensions a part of the event object
* test: convert all tests to typescript
* examples: update all examples with latest API changes
* docs: update README with latest API changes
* src: add prettier for code style and fix a lot of linting errors
* lib: move data decoding to occur within the CloudEvent object

Signed-off-by: Lance Ball <[email protected]>
@lance lance marked this pull request as ready for review June 24, 2020 21:02
@lance
Copy link
Member Author

lance commented Jun 24, 2020

@cloudevents/sdk-javascript-maintainers I have completed all of the items on the checklist and addressed about 95% of the comments/nits. Please have a look. This is ready for final review and landing. ✈️

const properties = { ...event };

this.id = (properties.id as string) || uuidv4();
delete properties.id;
Copy link
Member

Choose a reason for hiding this comment

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

These deletions seem unnecessary and do not affect the logic of the function. Do we really need to delete them? The whole properties const is only scoped for this block and will be deleted at the end of the block naturally.

Copy link
Member Author

Choose a reason for hiding this comment

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

As noted in the comment above, it is necessary to delete them if we want to have extensions as siblings of the event properties. We remove all of the known properties, and what's left are the extensions.

@grant
Copy link
Member

grant commented Jun 24, 2020

Looks good! 👍 A few comments.

Copy link
Contributor

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

The only thing is that the examples won't work until we do a release and update the version there. But overall, LGTM!

@lance
Copy link
Member Author

lance commented Jun 29, 2020

Deep breaths.... landing this.

@lance lance merged commit 276b810 into cloudevents:master Jun 29, 2020
@lance lance mentioned this pull request Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request typescript Issues related to TypeScript usage or implementation
Projects
None yet
4 participants