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

lib!: change CloudEvent to use direct object notation and get/set properties #172

Merged
merged 4 commits into from
May 22, 2020

Conversation

lance
Copy link
Member

@lance lance commented May 20, 2020

This commit makes a substantial change to the API, changing the CloudEvent class
to accept properties as an object in the constructor. For example:

const CloudEvent = require('cloudevents-sdk');

// all event properties except extensions may be set in the constructor
const event = new CloudEvent({
  source: 'http://my.event.source',
  type: 'test-event-type'
});

// get and set all properties standard property notation
console.log(event.time); // the event timestamp
event.subject = 'my event subject';

This change includes a new test file to explicitly test this interface,
as well as new documentation.

Fixes: #65
Fixes: #148
Fixes: #135
Fixes: #88

@lance lance requested review from a team, danbev, grant and fabiojose and removed request for a team May 20, 2020 19:43
@lance lance self-assigned this May 20, 2020
@lance lance added the type/enhancement New feature or request label May 20, 2020
…perties

This commit makes a substantial change to the API, changing the CloudEvent class
to accept properties as an object in the constructor. For example:

```js
const CloudEvent = require('cloudevents-sdk');

// all event properties except extensions may be set in the constructor
const event = new CloudEvent({
  source: 'http://my.event.source',
  type: 'test-event-type'
});

// get and set all properties standard property notation
console.log(event.time); // the event timestamp
event.subject = 'my event subject';
```

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance force-pushed the 65-direct-object-creation branch from a32dbb6 to 59d5fab Compare May 20, 2020 20:06
lance added 2 commits May 20, 2020 16:20
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
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.

LGTM.
Aside: It's hard to review changes that modify HTML. Can we update HTML changes in a different branch/PR or something?

@lance
Copy link
Member Author

lance commented May 21, 2020

I realize there are a lot of changes in the HTML, however, the HTML is auto-generated, so usually I don't think it's necessary to spend time reviewing it. It's just reflecting what's in the code. Typically, I will just click the "Viewed" checkbox on the PR so they don't get in the way. Since our docs are configured to be published at https://cloudevents.github.io/sdk-javascript/ we need to have them on master instead of another branch. 🤷‍♂️

@grant
Copy link
Member

grant commented May 21, 2020

I would really like no autogenerated files in source control. We can think of some other way to get the docs besides this. Not sure if others agree.

@lance
Copy link
Member Author

lance commented May 21, 2020

I think it's pretty common to use the docs/ dir as a place for a project's website. That's what sdk-go does, for example. Of course, they have godoc.org to publish their API which we don't have - and which is why our generated documentation lives in docs/. I don't think these will be changing regularly - only when there are big API changes like this.

@lance
Copy link
Member Author

lance commented May 21, 2020

Since it's such a big change, if you just want to see how the API is used, I added some tests that just exercise the new interface. test/cloud_event_test.js

@lance lance requested a review from helio-frota May 21, 2020 21:00
@@ -14,8 +14,7 @@ function check(payload, headers, receiver) {
const sanityHeaders = sanityAndClone(headers);

// Validation Level 1
if (!receiver.allowedContentTypes
.includes(sanityHeaders[HEADER_CONTENT_TYPE])) {
if (!receiver.allowedContentTypes.includes(sanityHeaders[HEADER_CONTENT_TYPE])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, but I remember something like that in other file (?) : )

if ( not_receiver_allowed_includes foo )

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry missing the context here, I remember that we saw something like that in other file.
and you extracted some variables to improve the readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lance I found it #134 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh gotcha. The difference here is that this is for a structured receiver. The PR you point to is modifying a binary event receiver where an event is sent without any content-type header. For structured receivers, the content-type must be there.

/**
* An instance of a CloudEvent.
* An CloudEvent describes event data in common formats to provide
* interopability across services, platforms and systems.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo interopability

@helio-frota
Copy link
Contributor

regarding some core business changes that may exist here and there I have no much idea, other than that it looks good the move from prototype to ES6 classes. LGTM after the minor changes 👍

Signed-off-by: Lance Ball <lball@redhat.com>
@helio-frota helio-frota self-requested a review May 22, 2020 16:59
@lance lance merged commit abc114b into cloudevents:master May 22, 2020
@lance lance deleted the 65-direct-object-creation branch May 22, 2020 17:03
@github-actions github-actions bot mentioned this pull request Sep 17, 2020
@github-actions github-actions bot mentioned this pull request Oct 1, 2020
@github-actions github-actions bot mentioned this pull request Oct 13, 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
Projects
None yet
3 participants