-
Notifications
You must be signed in to change notification settings - Fork 69
Validate a Cloud Event on creation and make it read only with a method to augment it #234
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
Conversation
|
38952e9
to
fb3dc6d
Compare
Going in a different direction. Not using Proxy any more but using the "cloneWith" method instead. I'll need to update the tests |
615ab02
to
3116ffc
Compare
For this PR i had originally thought to add the validation in #228 and #229, but i think those should be its own PR and this one should just focus on calling validate during object creation as well as making the object read-only. I have another branch with the extension name validation ready to go once this gets in |
Ping @cloudevents/sdk-javascript-maintainers PTAL |
8d32ac0
to
c20a10f
Compare
test/http_binding_1.ts
Outdated
@@ -35,8 +35,7 @@ const cloudevent = new CloudEvent({ | |||
dataschema, | |||
data, | |||
}); | |||
cloudevent[ext1Name] = ext1Value; | |||
cloudevent[ext2Name] = ext2Value; | |||
cloudevent = cloudevent.cloneWith({ [ext1Name]: ext1Value, [ext2Name]: ext2Value }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we just add this to the original CloudEvent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably could. Looks like a leftover of when you couldn't add extensions during construction
test/spec_03_tests.ts
Outdated
cloudevent.datacontentencoding = Constants.ENCODING_BASE64; | ||
cloudevent = cloudevent.cloneWith({ | ||
datacontentencoding: Constants.ENCODING_BASE64, | ||
data: "SSB3YXMgZnVubnkg8J+Ygg==", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, can you post the original string, then btoa
it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other tests that already have the string encoded, so the precedent was already set. If this is a blocker, then we can create another PR to update the other tests as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO if other PRs are doing this?
It's still not ideal as I can't read or understand SSB3...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - nice changes to the test files using cloneWith
instead of mucking around with a single event, changing it as needed for each test.
433ecc3
to
df8a2fb
Compare
@cloudevents/sdk-javascript-maintainers how do we feel about merging this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. I've noted a few places where the tests got looser (just testing expect.to.throw()
instead of the type of Error and message). I think these should retain the original intent.These and the others I didn't call out should probably be changed to the stricter throw(ValidationError, "invalid payload")
.
df8a2fb
to
783095e
Compare
@lance i updated the tests to make sure they are throwing a TypeError, which is the error that will be thrown when trying to delete a property on a frozen object. |
@grant are you ok with this PR. Your comments were related to how some of the tests were written, which i've tried to give an explanation for. If this is still a blocker, maybe we could address those in a separate PR? |
Looks good to me. Thanks for the PR! |
3daed0b
to
5ec847e
Compare
…nt itself. BREAKING CHANGE: * This change makes the CloudEvent Read-only and validates the input during object creation. * To augment an already created CloudEvent object, we have added a `cloneWith` method that takes attributes to add/update. Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
5ec847e
to
d0099e2
Compare
During the creation of a CloudEvent, the validate method is now called. The object is also frozen to make it read-only.
A new method
cloneWith
has been added which can be used to add/update attributes such as extensions and will return a new Cloud Event Objectfixes #233
related #29
Signed-off-by: Lucas Holmquist lholmqui@redhat.com