Skip to content

fix: Make CloudEvent data field immutable and enumerable #516

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

PSanetra
Copy link
Contributor

Proposed Changes

  • CloudEvent class:
    • Make data field immutable like the other fields in the class
    • Make data field enumerable via Object.keys() and Object.entries()
    • toJSON() does not return a data field anymore if data_base64 is set to comply with the JSON format spec 3.1.1 Out of this follows that the presence of the data and data_base64 members is mutually exclusive in a JSON serialized CloudEvent.

Fixes #515

@PSanetra PSanetra force-pushed the make-cloudevent-comparable branch from 684e5cf to 02e8229 Compare October 31, 2022 14:48
Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

@PSanetra thanks for this contribution! The atob function does not exist in Node.js LTS prior to version 16. Could you please add atob to dependencies and @types/atob to the dev-dependencies section, and add an import statement in validation.ts? This should get CI passing.

….keys() (cloudevents#515)

Signed-off-by: Philip Sanetra <code@psanetra.de>
@PSanetra PSanetra force-pushed the make-cloudevent-comparable branch from 02e8229 to 69b2c6e Compare November 1, 2022 10:04
@PSanetra
Copy link
Contributor Author

PSanetra commented Nov 1, 2022

@lance I have changed the code to support node.js runtime and browser runtime without a additional dependency.

Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

Great addition. Thank you.

@lance lance merged commit 2d5fab1 into cloudevents:main Nov 1, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid jest#13535 and planttheidea/fast-equals#91
3 participants