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

Use @bufbuild #337

Merged
merged 17 commits into from
Feb 21, 2023
Merged

Use @bufbuild #337

merged 17 commits into from
Feb 21, 2023

Conversation

felicio
Copy link
Collaborator

@felicio felicio commented Feb 3, 2023

Resolves #325

@@ -1,6 +1,6 @@
version: v1beta1

version: v1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Uses stable version (see https://docs.buf.build/generate/usage).

Comment on lines +1 to 10
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- ENUM_ZERO_VALUE_SUFFIX
- ENUM_VALUE_PREFIX
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related buf commands work relative to the file's location, recursively. So instead of excluding all found files, for example from node_modules, this config is placed next our .proto definitions to match only those.

import type { Client } from '../client'
import type { PlainMessage } from '@bufbuild/protobuf'
Copy link
Collaborator Author

@felicio felicio Feb 6, 2023

Choose a reason for hiding this comment

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

⚠️ Uses PlainMessage utility type, because classes are passed around and @bufbuild/protoc-gen-es does not generate interfaces like protons does.

See "OK, so why not generate both classes and interfaces?".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I must admit that I like how protons uses same name for both the interface and encoding function under a namespace, and thus allowing one import, by relying on type inference:

the compiler infers whether it refers to the type alias or the namespace based on the usage. – https://stackoverflow.com/questions/62604227/namespace-with-the-same-name-as-type-alias-in-the-same-file

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder why they didn't consider ES modules as a valid approach...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

clock: this.setClock(this.#clock),
chatId,
communityId: hexToBytes(this.id),
ensName: '',
})
}).toBinary()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ Payloads are encoded with new and toBinary() instead of encode().

// decode
const decodedPayload = CommunityDescription.decode(messageToDecode)
const decodedPayload = CommunityDescription.fromBinary(messageToDecode)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ Payloads are decoded with fromBinary() instead of decode().

*
* @generated from field: ChatMessage.ContentType content_type = 8;
*/
contentType = ChatMessage_ContentType.UNKNOWN_CONTENT_TYPE;
Copy link
Collaborator Author

@felicio felicio Feb 6, 2023

Choose a reason for hiding this comment

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

@felicio felicio changed the title WIP: Use @bufbuild Use @bufbuild Feb 6, 2023
@prichodko
Copy link
Collaborator

What does it use for a runtime?

@prichodko
Copy link
Collaborator

I would love to know the size of generated files. I can help with this if necessary.

@prichodko
Copy link
Collaborator

Thanks for doing this. Feels good to get rid of this debt.

@felicio
Copy link
Collaborator Author

felicio commented Feb 7, 2023

I would love to know the size of generated files. I can help with this if necessary.

Does

answer the bundle size, and

the files size?

Or did you have something else in mind?

@felicio
Copy link
Collaborator Author

felicio commented Feb 7, 2023

What does it use for a runtime?

@bufbuild/protobuf

@prichodko
Copy link
Collaborator

In the end, what matters is not the number of lines, but the final size after all dependencies are bundled and optimized. The comment in #325 is a good indicator. 👍

@fryorcraken
Copy link

I see some size gain from this change. Anything else?

@felicio felicio mentioned this pull request Feb 10, 2023
@felicio
Copy link
Collaborator Author

felicio commented Feb 10, 2023

@fryorcraken

I see some size gain from this change. Anything else?

For this repo:

@fryorcraken
Copy link

fryorcraken commented Feb 17, 2023

thanks @felicio . All great reason.

Could you help me understand this technical debt?

single runtime (technical debt)

Are you saying bufbuild uses async? However, everything is done in JavaScript runtime, right? so how does it help?

@felicio
Copy link
Collaborator Author

felicio commented Feb 17, 2023

@fryorcraken

Could you help me understand this time?

I see how it could be confusing now. It just that we've experimented with different protobuf runtime (i.e. protons-runtime) but still left protobufjs (at diff version) in the project too handling CommunityDescription, for instance.

With this PR, I'm proposing to drop the two for just one – @bufbuild/protobuf.

@prichodko prichodko merged commit effd3ea into status-im:main Feb 21, 2023
Copy link
Collaborator

@prichodko prichodko left a comment

Choose a reason for hiding this comment

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

👍

"long": "^5.2.0",
"protobufjs": "^6.11.3",
"protons-runtime": "^1.0.4"
"long": "^5.2.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need Long package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed at 2bdcc54

felicio added a commit to felicio/status-web that referenced this pull request May 15, 2023
* remove old `communities.proto`

* fix `protos` npm script

* apply `protos` changes overwriting `Record<>` patches

* update proto files

* regenerate files

* update `protons*` packages

* regen files

* use `protons` generate communities

* add `@bufbuild*` packages

* update `buf` yaml files

* generate `@bufbuild` files

* use `@bufbuild` files

* format

* remove `protobufjs`

* remove `protons`

* resolve build errors

* fix image content type
@felicio felicio self-assigned this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use single protobuf generator and runtime
3 participants