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

feat: extensions #808

Merged
merged 2 commits into from
Apr 1, 2023
Merged

feat: extensions #808

merged 2 commits into from
Apr 1, 2023

Conversation

davidzeng0
Copy link
Contributor

@davidzeng0 davidzeng0 commented Mar 26, 2023

Can be automatically merged

@davidzeng0
Copy link
Contributor Author

davidzeng0 commented Mar 26, 2023

I hope you like the way I implemented it, if you want any changes let me know.

One possible problematic area of note is that the code parses both packed and unpacked extensions, and packed is always parsed before the unpacked, leading to possible re-ordering. If I remember correctly, protobuf's website said that applications should not expect field order to be preserved, so it shouldn't be a problem.

ts-proto-decriptors should be updated to add extensions

@davidzeng0
Copy link
Contributor Author

Any thoughts on this?

@stephenh
Copy link
Owner

Hey @davidzeng0 ; from my initial scan of the tests, it looks pretty great, very standard approach to protobuf extensions AFAIU (I've not actually used them personally before). It'll probably be the weekend before I dive in a bit more, but its great to have this feature. Thank you!

@davidzeng0
Copy link
Contributor Author

Alright 👍

@davidzeng0
Copy link
Contributor Author

Rebased and fixed tests

Copy link
Owner

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

This looks great!

Awhile ago I'd thought about maybe trying to figure out an alternative API to the stock Extension.set(message, someConst, value), like something like:

const message = ...
const extended = Extension.wrap(message)
extended.someField = 1
extended.otherField = 2

But I don't think that's even possible b/c the proto file doesn't even have a name for what the wrapped type would be, i.e. something like:

extension MyNiceName extends Extendable {
  string someField = 1 
}

Would let us know to use MyNiceName as the type name for all of the someField / etc. fields ... but that is just not there/something they thought to include in the proto file. 🤔 So 🤷 I think that puts a damper on any cute/alternative APIs.

@stephenh stephenh merged commit f956128 into stephenh:main Apr 1, 2023
stephenh pushed a commit that referenced this pull request Apr 1, 2023
# [1.146.0](v1.145.0...v1.146.0) (2023-04-01)

### Features

* extensions ([#808](#808)) ([f956128](f956128))
@stephenh
Copy link
Owner

stephenh commented Apr 1, 2023

🎉 This PR is included in version 1.146.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@davidzeng0
Copy link
Contributor Author

Thanks for being patient with me :)

@davidzeng0
Copy link
Contributor Author

A ts-proto-descriptors bump with outputExtensions=true would be great

@davidzeng0 davidzeng0 deleted the extensions branch April 1, 2023 20:44
@davidzeng0
Copy link
Contributor Author

ts-proto-descriptors bump: #814

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants