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

Expose experimental syntax "editions" in descriptor sets #621

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

timostamm
Copy link
Member

@timostamm timostamm commented Nov 17, 2023

This change exposes the editions syntax in a DescriptorSet, the wrapper around protobuf file descriptor messages provided by createDescriptorSet from @bufbuild/protobuf.

The type DescFile receives a new property:

  /**
   * The edition of the protobuf file. Will be EDITION_PROTO2 for syntax="proto2",
   * EDITION_PROTO3 for syntax="proto3";
   */
  readonly edition: Omit<Edition, ...>;

The syntax property is updated to include "editions" in the union type:

  /**
   * The syntax specified in the protobuf source.
   */
  readonly syntax: "proto3" | "proto2" | "editions";

For example, a file with syntax="proto3" will have the properties syntax: "proto3" and edition: Edition.EDITION_PROTO3. A file with edition="2023" will have the properties syntax: "editions" and edition: Edition.EDITION_2023.

Note that this change may cause compile time errors in your code, even if you are not using editions yet.

Edition FeatureSets are not exposed yet. protoc-gen-es cannot generate code for editions yet. This change just allows createDescriptorSet to wrap descriptors using editions.

@timostamm timostamm requested review from smaye81, a team, Alfus and chrispine November 17, 2023 16:20
Comment on lines +888 to +890
case "editions":
// TODO support edition featureset
return true;
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would probably unify this with "proto3" so it is at least closer to accurate. By default in editions (without element-level feature override), it behaves the same as proto3.

Copy link
Member Author

Choose a reason for hiding this comment

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

In EDITION_2023 it does, but in EDITION_PROTO2 it does not 😛 Will update this logic in the next step, where this value will be plucked from FeatureSetDefaults.

Copy link
Member

Choose a reason for hiding this comment

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

But if the edition is EDITION_PROTO2, the syntax will not be "editions"; it will be "proto2".

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right about "proto2" of course.

Here is the new implementation of isPackedFieldByDefault. It uses the seeded default value of repeated_field_encoding for the edition, including EDITION_PROTO2, EDITION_PROTO3, EDITION_2023, and any future edition.

The implementation is shorter and seems less ambiguous. I guessed it would, which is why I wanted to hold off modifying it in this PR. I should have explained better.

packages/protoc-gen-es/src/javascript.ts Show resolved Hide resolved
@timostamm timostamm merged commit 8a23052 into main Nov 20, 2023
5 checks passed
@timostamm timostamm deleted the tstamm/expose-syntax-editions-in-desc branch November 20, 2023 14:14
@timostamm timostamm changed the title Expose syntax "editions" in descriptor sets Expose experimental syntax "editions" in descriptor sets Nov 22, 2023
@timostamm timostamm mentioned this pull request Nov 30, 2023
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.

2 participants