diff --git a/packages/protobuf-bench/README.md b/packages/protobuf-bench/README.md index a779e08bd..57efa9613 100644 --- a/packages/protobuf-bench/README.md +++ b/packages/protobuf-bench/README.md @@ -10,5 +10,5 @@ server would usually do. | code generator | bundle size | minified | compressed | |---------------------|------------------------:|-----------------------:|-------------------:| -| protobuf-es | 96,441 b | 41,150 b | 10,720 b | +| protobuf-es | 96,775 b | 41,274 b | 10,739 b | | protobuf-javascript | 394,384 b | 288,654 b | 45,122 b | diff --git a/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts b/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts index b4512061e..cbb7596ca 100644 --- a/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts +++ b/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts @@ -1680,45 +1680,45 @@ export class TestAllRequiredTypesProto2 extends Message [ - { no: 1, name: "required_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "required_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */ }, - { no: 3, name: "required_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, - { no: 4, name: "required_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 5, name: "required_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */ }, - { no: 6, name: "required_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */ }, - { no: 7, name: "required_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 8, name: "required_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */ }, - { no: 9, name: "required_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */ }, - { no: 10, name: "required_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */ }, - { no: 11, name: "required_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */ }, - { no: 12, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */ }, - { no: 13, name: "required_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 14, name: "required_string", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 15, name: "required_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, - { no: 18, name: "required_nested_message", kind: "message", T: TestAllRequiredTypesProto2_NestedMessage }, - { no: 19, name: "required_foreign_message", kind: "message", T: ForeignMessageProto2 }, - { no: 21, name: "required_nested_enum", kind: "enum", T: proto2.getEnumType(TestAllRequiredTypesProto2_NestedEnum) }, - { no: 22, name: "required_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnumProto2) }, - { no: 24, name: "required_string_piece", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2 }, + { no: 1, name: "required_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "required_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, req: true }, + { no: 3, name: "required_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true }, + { no: 4, name: "required_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, req: true }, + { no: 5, name: "required_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, req: true }, + { no: 6, name: "required_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, req: true }, + { no: 7, name: "required_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 8, name: "required_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, req: true }, + { no: 9, name: "required_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, req: true }, + { no: 10, name: "required_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, req: true }, + { no: 11, name: "required_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, req: true }, + { no: 12, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true }, + { no: 13, name: "required_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true }, + { no: 14, name: "required_string", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 15, name: "required_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, + { no: 18, name: "required_nested_message", kind: "message", T: TestAllRequiredTypesProto2_NestedMessage, req: true }, + { no: 19, name: "required_foreign_message", kind: "message", T: ForeignMessageProto2, req: true }, + { no: 21, name: "required_nested_enum", kind: "enum", T: proto2.getEnumType(TestAllRequiredTypesProto2_NestedEnum), req: true }, + { no: 22, name: "required_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnumProto2), req: true }, + { no: 24, name: "required_string_piece", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2, req: true }, { no: 28, name: "optional_recursive_message", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, - { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true }, - { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: -123456789 }, - { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 2123456789 }, - { no: 244, name: "default_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, default: protoInt64.uParse("10123456789123456789") }, - { no: 245, name: "default_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, default: -123456789 }, - { no: 246, name: "default_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 247, name: "default_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, default: 2123456789 }, - { no: 248, name: "default_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, default: protoInt64.uParse("10123456789123456789") }, - { no: 249, name: "default_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, default: -123456789 }, - { no: 250, name: "default_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 251, name: "default_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, default: 9000000000 }, - { no: 252, name: "default_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, default: 7e+22 }, - { no: 253, name: "default_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: true }, - { no: 254, name: "default_string", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Rosebud" }, - { no: 255, name: "default_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0x6A, 0x6F, 0x73, 0x68, 0x75, 0x61]) }, + { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true, req: true }, + { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true, default: -123456789 }, + { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true, default: 2123456789 }, + { no: 244, name: "default_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, req: true, default: protoInt64.uParse("10123456789123456789") }, + { no: 245, name: "default_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, req: true, default: -123456789 }, + { no: 246, name: "default_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 247, name: "default_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true, default: 2123456789 }, + { no: 248, name: "default_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, req: true, default: protoInt64.uParse("10123456789123456789") }, + { no: 249, name: "default_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, req: true, default: -123456789 }, + { no: 250, name: "default_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 251, name: "default_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, req: true, default: 9000000000 }, + { no: 252, name: "default_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true, default: 7e+22 }, + { no: 253, name: "default_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true, default: true }, + { no: 254, name: "default_string", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true, default: "Rosebud" }, + { no: 255, name: "default_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true, default: new Uint8Array([0x6A, 0x6F, 0x73, 0x68, 0x75, 0x61]) }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2 { @@ -1799,8 +1799,8 @@ export class TestAllRequiredTypesProto2_NestedMessage extends Message [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "corecursive", kind: "message", T: TestAllRequiredTypesProto2 }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "corecursive", kind: "message", T: TestAllRequiredTypesProto2, req: true }, { no: 3, name: "optional_corecursive", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, ]); @@ -1845,8 +1845,8 @@ export class TestAllRequiredTypesProto2_Data extends Message [ - { no: 202, name: "group_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 203, name: "group_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, + { no: 202, name: "group_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 203, name: "group_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2_Data { @@ -1916,7 +1916,7 @@ export class TestAllRequiredTypesProto2_MessageSetCorrectExtension1 extends Mess static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.MessageSetCorrectExtension1"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 25, name: "str", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 25, name: "str", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2_MessageSetCorrectExtension1 { @@ -1962,7 +1962,7 @@ export class TestAllRequiredTypesProto2_MessageSetCorrectExtension2 extends Mess static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.MessageSetCorrectExtension2"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 9, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 9, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2_MessageSetCorrectExtension2 { diff --git a/packages/protobuf-test/src/gen/js/extra/proto2_pb.js b/packages/protobuf-test/src/gen/js/extra/proto2_pb.js index bdf323b8f..402142afd 100644 --- a/packages/protobuf-test/src/gen/js/extra/proto2_pb.js +++ b/packages/protobuf-test/src/gen/js/extra/proto2_pb.js @@ -84,10 +84,10 @@ export const Proto2OptionalMessage = proto2.makeMessageType( export const Proto2RequiredMessage = proto2.makeMessageType( "spec.Proto2RequiredMessage", () => [ - { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, - { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum) }, - { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage }, + { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, + { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum), req: true }, + { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage, req: true }, ], ); @@ -97,10 +97,10 @@ export const Proto2RequiredMessage = proto2.makeMessageType( export const Proto2RequiredDefaultsMessage = proto2.makeMessageType( "spec.Proto2RequiredDefaultsMessage", () => [ - { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "hello \" */ " }, - { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0x00, 0x78, 0x5C, 0x78, 0x78, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x08, 0x0C, 0x0A, 0x0D, 0x09, 0x0B]) }, - { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum), default: Proto2Enum.YES }, - { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage }, + { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true, default: "hello \" */ " }, + { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true, default: new Uint8Array([0x00, 0x78, 0x5C, 0x78, 0x78, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x08, 0x0C, 0x0A, 0x0D, 0x09, 0x0B]) }, + { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum), req: true, default: Proto2Enum.YES }, + { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage, req: true }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/descriptor_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/descriptor_pb.js index 2db05cdde..f7e3d89da 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/descriptor_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/descriptor_pb.js @@ -601,8 +601,8 @@ export const UninterpretedOption = proto2.makeMessageType( export const UninterpretedOption_NamePart = proto2.makeMessageType( "google.protobuf.UninterpretedOption.NamePart", () => [ - { no: 1, name: "name_part", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "is_extension", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, + { no: 1, name: "name_part", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 2, name: "is_extension", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true }, ], {localName: "UninterpretedOption_NamePart"}, ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/map_lite_unittest_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/map_lite_unittest_pb.js index 83bedc009..1699f723d 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/map_lite_unittest_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/map_lite_unittest_pb.js @@ -159,9 +159,9 @@ export const TestMessageMapLite = proto2.makeMessageType( export const TestRequiredLite = proto2.makeMessageType( "protobuf_unittest.TestRequiredLite", () => [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 3, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 3, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js index 61a10ccdf..e362ef2d0 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js @@ -363,45 +363,45 @@ export const ProtoWithKeywords = proto2.makeMessageType( export const TestAllRequiredTypesProto2 = proto2.makeMessageType( "protobuf_test_messages.proto2.TestAllRequiredTypesProto2", () => [ - { no: 1, name: "required_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "required_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */ }, - { no: 3, name: "required_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, - { no: 4, name: "required_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 5, name: "required_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */ }, - { no: 6, name: "required_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */ }, - { no: 7, name: "required_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 8, name: "required_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */ }, - { no: 9, name: "required_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */ }, - { no: 10, name: "required_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */ }, - { no: 11, name: "required_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */ }, - { no: 12, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */ }, - { no: 13, name: "required_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 14, name: "required_string", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 15, name: "required_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, - { no: 18, name: "required_nested_message", kind: "message", T: TestAllRequiredTypesProto2_NestedMessage }, - { no: 19, name: "required_foreign_message", kind: "message", T: ForeignMessageProto2 }, - { no: 21, name: "required_nested_enum", kind: "enum", T: proto2.getEnumType(TestAllRequiredTypesProto2_NestedEnum) }, - { no: 22, name: "required_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnumProto2) }, - { no: 24, name: "required_string_piece", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2 }, + { no: 1, name: "required_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "required_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, req: true }, + { no: 3, name: "required_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true }, + { no: 4, name: "required_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, req: true }, + { no: 5, name: "required_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, req: true }, + { no: 6, name: "required_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, req: true }, + { no: 7, name: "required_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 8, name: "required_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, req: true }, + { no: 9, name: "required_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, req: true }, + { no: 10, name: "required_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, req: true }, + { no: 11, name: "required_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, req: true }, + { no: 12, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true }, + { no: 13, name: "required_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true }, + { no: 14, name: "required_string", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 15, name: "required_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, + { no: 18, name: "required_nested_message", kind: "message", T: TestAllRequiredTypesProto2_NestedMessage, req: true }, + { no: 19, name: "required_foreign_message", kind: "message", T: ForeignMessageProto2, req: true }, + { no: 21, name: "required_nested_enum", kind: "enum", T: proto2.getEnumType(TestAllRequiredTypesProto2_NestedEnum), req: true }, + { no: 22, name: "required_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnumProto2), req: true }, + { no: 24, name: "required_string_piece", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2, req: true }, { no: 28, name: "optional_recursive_message", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, - { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true }, - { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: -123456789 }, - { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 2123456789 }, - { no: 244, name: "default_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, default: protoInt64.uParse("10123456789123456789") }, - { no: 245, name: "default_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, default: -123456789 }, - { no: 246, name: "default_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 247, name: "default_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, default: 2123456789 }, - { no: 248, name: "default_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, default: protoInt64.uParse("10123456789123456789") }, - { no: 249, name: "default_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, default: -123456789 }, - { no: 250, name: "default_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 251, name: "default_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, default: 9000000000 }, - { no: 252, name: "default_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, default: 7e+22 }, - { no: 253, name: "default_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: true }, - { no: 254, name: "default_string", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Rosebud" }, - { no: 255, name: "default_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0x6A, 0x6F, 0x73, 0x68, 0x75, 0x61]) }, + { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true, req: true }, + { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true, default: -123456789 }, + { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true, default: 2123456789 }, + { no: 244, name: "default_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, req: true, default: protoInt64.uParse("10123456789123456789") }, + { no: 245, name: "default_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, req: true, default: -123456789 }, + { no: 246, name: "default_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 247, name: "default_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true, default: 2123456789 }, + { no: 248, name: "default_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, req: true, default: protoInt64.uParse("10123456789123456789") }, + { no: 249, name: "default_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, req: true, default: -123456789 }, + { no: 250, name: "default_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 251, name: "default_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, req: true, default: 9000000000 }, + { no: 252, name: "default_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true, default: 7e+22 }, + { no: 253, name: "default_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true, default: true }, + { no: 254, name: "default_string", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true, default: "Rosebud" }, + { no: 255, name: "default_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true, default: new Uint8Array([0x6A, 0x6F, 0x73, 0x68, 0x75, 0x61]) }, ], ); @@ -424,8 +424,8 @@ export const TestAllRequiredTypesProto2_NestedEnum = proto2.makeEnum( export const TestAllRequiredTypesProto2_NestedMessage = proto2.makeMessageType( "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.NestedMessage", () => [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "corecursive", kind: "message", T: TestAllRequiredTypesProto2 }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "corecursive", kind: "message", T: TestAllRequiredTypesProto2, req: true }, { no: 3, name: "optional_corecursive", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, ], {localName: "TestAllRequiredTypesProto2_NestedMessage"}, @@ -439,8 +439,8 @@ export const TestAllRequiredTypesProto2_NestedMessage = proto2.makeMessageType( export const TestAllRequiredTypesProto2_Data = proto2.makeMessageType( "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.Data", () => [ - { no: 202, name: "group_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 203, name: "group_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, + { no: 202, name: "group_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 203, name: "group_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true }, ], {localName: "TestAllRequiredTypesProto2_Data"}, ); @@ -462,7 +462,7 @@ export const TestAllRequiredTypesProto2_MessageSetCorrect = proto2.makeMessageTy export const TestAllRequiredTypesProto2_MessageSetCorrectExtension1 = proto2.makeMessageType( "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.MessageSetCorrectExtension1", () => [ - { no: 25, name: "str", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 25, name: "str", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, ], {localName: "TestAllRequiredTypesProto2_MessageSetCorrectExtension1"}, ); @@ -482,7 +482,7 @@ export const TestAllRequiredTypesProto2_MessageSetCorrectExtension1_message_set_ export const TestAllRequiredTypesProto2_MessageSetCorrectExtension2 = proto2.makeMessageType( "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.MessageSetCorrectExtension2", () => [ - { no: 9, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 9, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ], {localName: "TestAllRequiredTypesProto2_MessageSetCorrectExtension2"}, ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js index 4943991fb..f269379af 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js @@ -376,7 +376,7 @@ export const NestedOptionType_nested_extension = proto2.makeExtension( export const OldOptionType = proto2.makeMessageType( "protobuf_unittest.OldOptionType", () => [ - { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(OldOptionType_TestEnum) }, + { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(OldOptionType_TestEnum), req: true }, ], ); @@ -398,7 +398,7 @@ export const OldOptionType_TestEnum = proto2.makeEnum( export const NewOptionType = proto2.makeMessageType( "protobuf_unittest.NewOptionType", () => [ - { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(NewOptionType_TestEnum) }, + { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(NewOptionType_TestEnum), req: true }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js index 78cd9cf0f..f2d26c03b 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js @@ -301,7 +301,7 @@ export const TestDeprecatedLite = proto2.makeMessageType( "protobuf_unittest.TestDeprecatedLite", () => [ { no: 1, name: "deprecated_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "deprecated_field2", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 2, name: "deprecated_field2", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 3, name: "deprecated_field3", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 4, name: "deprecated_field4", kind: "message", T: TestDeprecatedLite, opt: true }, ], @@ -315,7 +315,7 @@ export const TestDeprecatedLite = proto2.makeMessageType( export const TestParsingMergeLite = proto2.makeMessageType( "protobuf_unittest.TestParsingMergeLite", () => [ - { no: 1, name: "required_all_types", kind: "message", T: TestAllTypesLite }, + { no: 1, name: "required_all_types", kind: "message", T: TestAllTypesLite, req: true }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypesLite, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypesLite, repeated: true }, { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMergeLite_OptionalGroup, delimited: true, opt: true }, @@ -442,7 +442,7 @@ export const TestEmptyMessageWithExtensionsLite = proto2.makeMessageType( export const V1MessageLite = proto2.makeMessageType( "protobuf_unittest.V1MessageLite", () => [ - { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 2, name: "enum_field", kind: "enum", T: proto2.getEnumType(V1EnumLite), opt: true, default: V1EnumLite.V1_FIRST }, ], ); @@ -453,7 +453,7 @@ export const V1MessageLite = proto2.makeMessageType( export const V2MessageLite = proto2.makeMessageType( "protobuf_unittest.V2MessageLite", () => [ - { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 2, name: "enum_field", kind: "enum", T: proto2.getEnumType(V2EnumLite), opt: true, default: V2EnumLite.V2_FIRST }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js index 5f04f7b89..344eed541 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js @@ -107,7 +107,7 @@ export const TestMessageSetExtension3 = proto2.makeMessageType( "protobuf_unittest.TestMessageSetExtension3", () => [ { no: 35, name: "msg", kind: "message", T: NestedTestInt, opt: true }, - { no: 36, name: "required_int", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 36, name: "required_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ], ); @@ -138,8 +138,8 @@ export const RawMessageSet = proto2.makeMessageType( export const RawMessageSet_Item = proto2.makeMessageType( "protobuf_unittest.RawMessageSet.Item", () => [ - { no: 2, name: "type_id", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 3, name: "message", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, + { no: 2, name: "type_id", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 3, name: "message", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, ], {localName: "RawMessageSet_Item"}, ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_optimize_for_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_optimize_for_pb.js index e37efcbb3..cb7c5c6ba 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_optimize_for_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_optimize_for_pb.js @@ -62,7 +62,7 @@ export const TestOptimizedForSize_test_extension2 = proto2.makeExtension( export const TestRequiredOptimizedForSize = proto2.makeMessageType( "protobuf_unittest.TestRequiredOptimizedForSize", () => [ - { no: 1, name: "x", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "x", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js index c72487f69..f29a23b5b 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js @@ -630,7 +630,7 @@ export const TestNestedChildExtensionData = proto2.makeMessageType( export const TestRequiredEnum = proto2.makeMessageType( "protobuf_unittest.TestRequiredEnum", () => [ - { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(ForeignEnum) }, + { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(ForeignEnum), req: true }, { no: 2, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, ], ); @@ -643,7 +643,7 @@ export const TestRequiredEnum = proto2.makeMessageType( export const TestRequiredEnumNoMask = proto2.makeMessageType( "protobuf_unittest.TestRequiredEnumNoMask", () => [ - { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(TestRequiredEnumNoMask_NestedEnum) }, + { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(TestRequiredEnumNoMask_NestedEnum), req: true }, { no: 2, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, ], ); @@ -667,10 +667,10 @@ export const TestRequiredEnumNoMask_NestedEnum = proto2.makeEnum( export const TestRequiredEnumMulti = proto2.makeMessageType( "protobuf_unittest.TestRequiredEnumMulti", () => [ - { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum) }, + { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum), req: true }, { no: 3, name: "a_3", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum) }, - { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum) }, + { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum), req: true }, + { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum), req: true }, ], ); @@ -693,13 +693,13 @@ export const TestRequiredEnumMulti_NestedEnum = proto2.makeEnum( export const TestRequiredNoMaskMulti = proto2.makeMessageType( "protobuf_unittest.TestRequiredNoMaskMulti", () => [ - { no: 80, name: "required_fixed32_80", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 70, name: "required_fixed32_70", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 64, name: "required_enum_64", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum) }, - { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum) }, + { no: 80, name: "required_fixed32_80", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 70, name: "required_fixed32_70", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 64, name: "required_enum_64", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum), req: true }, + { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum), req: true }, { no: 3, name: "a_3", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum) }, - { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum) }, + { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum), req: true }, + { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum), req: true }, ], ); @@ -728,9 +728,9 @@ export const TestRequiredNoMaskMulti_NestedEnum = proto2.makeEnum( export const TestRequired = proto2.makeMessageType( "protobuf_unittest.TestRequired", () => [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 2, name: "dummy2", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 3, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 3, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 4, name: "dummy4", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 5, name: "dummy5", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 6, name: "dummy6", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, @@ -760,7 +760,7 @@ export const TestRequired = proto2.makeMessageType( { no: 30, name: "dummy30", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 31, name: "dummy31", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 32, name: "dummy32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 33, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 33, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 34, name: "optional_foreign", kind: "message", T: ForeignMessage, opt: true }, ], ); @@ -804,7 +804,7 @@ export const TestRequiredMessage = proto2.makeMessageType( () => [ { no: 1, name: "optional_message", kind: "message", T: TestRequired, opt: true }, { no: 2, name: "repeated_message", kind: "message", T: TestRequired, repeated: true }, - { no: 3, name: "required_message", kind: "message", T: TestRequired }, + { no: 3, name: "required_message", kind: "message", T: TestRequired, req: true }, ], ); @@ -1007,7 +1007,7 @@ export const TestIsInitialized_SubMessage = proto2.makeMessageType( export const TestIsInitialized_SubMessage_SubGroup = proto2.makeMessageType( "protobuf_unittest.TestIsInitialized.SubMessage.SubGroup", () => [ - { no: 2, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 2, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ], {localName: "TestIsInitialized_SubMessage_SubGroup"}, ); @@ -1561,7 +1561,7 @@ export const TestRequiredOneof = proto2.makeMessageType( export const TestRequiredOneof_NestedMessage = proto2.makeMessageType( "protobuf_unittest.TestRequiredOneof.NestedMessage", () => [ - { no: 1, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */ }, + { no: 1, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true }, ], {localName: "TestRequiredOneof_NestedMessage"}, ); @@ -1711,7 +1711,7 @@ export const TestRepeatedScalarDifferentTagSizes = proto2.makeMessageType( export const TestParsingMerge = proto2.makeMessageType( "protobuf_unittest.TestParsingMerge", () => [ - { no: 1, name: "required_all_types", kind: "message", T: TestAllTypes }, + { no: 1, name: "required_all_types", kind: "message", T: TestAllTypes, req: true }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypes, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypes, repeated: true }, { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMerge_OptionalGroup, delimited: true, opt: true }, diff --git a/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts b/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts index 11686ec9f..9f7eda410 100644 --- a/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts +++ b/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts @@ -273,10 +273,10 @@ export class Proto2RequiredMessage extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "spec.Proto2RequiredMessage"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, - { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum) }, - { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage }, + { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, + { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum), req: true }, + { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): Proto2RequiredMessage { @@ -328,10 +328,10 @@ export class Proto2RequiredDefaultsMessage extends Message [ - { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "hello \" */ " }, - { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0x00, 0x78, 0x5C, 0x78, 0x78, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x08, 0x0C, 0x0A, 0x0D, 0x09, 0x0B]) }, - { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum), default: Proto2Enum.YES }, - { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage }, + { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true, default: "hello \" */ " }, + { no: 2, name: "bytes_field", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true, default: new Uint8Array([0x00, 0x78, 0x5C, 0x78, 0x78, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x08, 0x0C, 0x0A, 0x0D, 0x09, 0x0B]) }, + { no: 3, name: "enum_field", kind: "enum", T: proto2.getEnumType(Proto2Enum), req: true, default: Proto2Enum.YES }, + { no: 4, name: "message_field", kind: "message", T: Proto2ChildMessage, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): Proto2RequiredDefaultsMessage { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/descriptor_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/descriptor_pb.ts index 6ab219d5f..d25653480 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/descriptor_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/descriptor_pb.ts @@ -2597,8 +2597,8 @@ export class UninterpretedOption_NamePart extends Message [ - { no: 1, name: "name_part", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "is_extension", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, + { no: 1, name: "name_part", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 2, name: "is_extension", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): UninterpretedOption_NamePart { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/map_lite_unittest_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/map_lite_unittest_pb.ts index fb8529ee0..944179e44 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/map_lite_unittest_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/map_lite_unittest_pb.ts @@ -565,9 +565,9 @@ export class TestRequiredLite extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestRequiredLite"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 3, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 3, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestRequiredLite { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts index b4512061e..cbb7596ca 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts @@ -1680,45 +1680,45 @@ export class TestAllRequiredTypesProto2 extends Message [ - { no: 1, name: "required_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "required_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */ }, - { no: 3, name: "required_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, - { no: 4, name: "required_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 5, name: "required_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */ }, - { no: 6, name: "required_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */ }, - { no: 7, name: "required_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 8, name: "required_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */ }, - { no: 9, name: "required_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */ }, - { no: 10, name: "required_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */ }, - { no: 11, name: "required_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */ }, - { no: 12, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */ }, - { no: 13, name: "required_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 14, name: "required_string", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 15, name: "required_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, - { no: 18, name: "required_nested_message", kind: "message", T: TestAllRequiredTypesProto2_NestedMessage }, - { no: 19, name: "required_foreign_message", kind: "message", T: ForeignMessageProto2 }, - { no: 21, name: "required_nested_enum", kind: "enum", T: proto2.getEnumType(TestAllRequiredTypesProto2_NestedEnum) }, - { no: 22, name: "required_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnumProto2) }, - { no: 24, name: "required_string_piece", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2 }, + { no: 1, name: "required_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "required_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, req: true }, + { no: 3, name: "required_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true }, + { no: 4, name: "required_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, req: true }, + { no: 5, name: "required_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, req: true }, + { no: 6, name: "required_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, req: true }, + { no: 7, name: "required_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 8, name: "required_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, req: true }, + { no: 9, name: "required_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, req: true }, + { no: 10, name: "required_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, req: true }, + { no: 11, name: "required_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, req: true }, + { no: 12, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true }, + { no: 13, name: "required_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true }, + { no: 14, name: "required_string", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 15, name: "required_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, + { no: 18, name: "required_nested_message", kind: "message", T: TestAllRequiredTypesProto2_NestedMessage, req: true }, + { no: 19, name: "required_foreign_message", kind: "message", T: ForeignMessageProto2, req: true }, + { no: 21, name: "required_nested_enum", kind: "enum", T: proto2.getEnumType(TestAllRequiredTypesProto2_NestedEnum), req: true }, + { no: 22, name: "required_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnumProto2), req: true }, + { no: 24, name: "required_string_piece", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2, req: true }, { no: 28, name: "optional_recursive_message", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, - { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true }, - { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: -123456789 }, - { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 2123456789 }, - { no: 244, name: "default_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, default: protoInt64.uParse("10123456789123456789") }, - { no: 245, name: "default_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, default: -123456789 }, - { no: 246, name: "default_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 247, name: "default_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, default: 2123456789 }, - { no: 248, name: "default_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, default: protoInt64.uParse("10123456789123456789") }, - { no: 249, name: "default_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, default: -123456789 }, - { no: 250, name: "default_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, default: protoInt64.parse("-9123456789123456789") }, - { no: 251, name: "default_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, default: 9000000000 }, - { no: 252, name: "default_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, default: 7e+22 }, - { no: 253, name: "default_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: true }, - { no: 254, name: "default_string", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Rosebud" }, - { no: 255, name: "default_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0x6A, 0x6F, 0x73, 0x68, 0x75, 0x61]) }, + { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true, req: true }, + { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true, default: -123456789 }, + { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true, default: 2123456789 }, + { no: 244, name: "default_uint64", kind: "scalar", T: 4 /* ScalarType.UINT64 */, req: true, default: protoInt64.uParse("10123456789123456789") }, + { no: 245, name: "default_sint32", kind: "scalar", T: 17 /* ScalarType.SINT32 */, req: true, default: -123456789 }, + { no: 246, name: "default_sint64", kind: "scalar", T: 18 /* ScalarType.SINT64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 247, name: "default_fixed32", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true, default: 2123456789 }, + { no: 248, name: "default_fixed64", kind: "scalar", T: 6 /* ScalarType.FIXED64 */, req: true, default: protoInt64.uParse("10123456789123456789") }, + { no: 249, name: "default_sfixed32", kind: "scalar", T: 15 /* ScalarType.SFIXED32 */, req: true, default: -123456789 }, + { no: 250, name: "default_sfixed64", kind: "scalar", T: 16 /* ScalarType.SFIXED64 */, req: true, default: protoInt64.parse("-9123456789123456789") }, + { no: 251, name: "default_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, req: true, default: 9000000000 }, + { no: 252, name: "default_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true, default: 7e+22 }, + { no: 253, name: "default_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true, default: true }, + { no: 254, name: "default_string", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true, default: "Rosebud" }, + { no: 255, name: "default_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true, default: new Uint8Array([0x6A, 0x6F, 0x73, 0x68, 0x75, 0x61]) }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2 { @@ -1799,8 +1799,8 @@ export class TestAllRequiredTypesProto2_NestedMessage extends Message [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 2, name: "corecursive", kind: "message", T: TestAllRequiredTypesProto2 }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 2, name: "corecursive", kind: "message", T: TestAllRequiredTypesProto2, req: true }, { no: 3, name: "optional_corecursive", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, ]); @@ -1845,8 +1845,8 @@ export class TestAllRequiredTypesProto2_Data extends Message [ - { no: 202, name: "group_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 203, name: "group_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, + { no: 202, name: "group_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 203, name: "group_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2_Data { @@ -1916,7 +1916,7 @@ export class TestAllRequiredTypesProto2_MessageSetCorrectExtension1 extends Mess static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.MessageSetCorrectExtension1"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 25, name: "str", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 25, name: "str", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2_MessageSetCorrectExtension1 { @@ -1962,7 +1962,7 @@ export class TestAllRequiredTypesProto2_MessageSetCorrectExtension2 extends Mess static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_test_messages.proto2.TestAllRequiredTypesProto2.MessageSetCorrectExtension2"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 9, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 9, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestAllRequiredTypesProto2_MessageSetCorrectExtension2 { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_custom_options_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_custom_options_pb.ts index adba9d37c..62a962330 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_custom_options_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_custom_options_pb.ts @@ -1123,7 +1123,7 @@ export class OldOptionType extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.OldOptionType"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(OldOptionType_TestEnum) }, + { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(OldOptionType_TestEnum), req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): OldOptionType { @@ -1176,7 +1176,7 @@ export class NewOptionType extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.NewOptionType"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(NewOptionType_TestEnum) }, + { no: 1, name: "value", kind: "enum", T: proto2.getEnumType(NewOptionType_TestEnum), req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): NewOptionType { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts index 051a561ee..2381bb760 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts @@ -1169,7 +1169,7 @@ export class TestDeprecatedLite extends Message { static readonly typeName = "protobuf_unittest.TestDeprecatedLite"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ { no: 1, name: "deprecated_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "deprecated_field2", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 2, name: "deprecated_field2", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 3, name: "deprecated_field3", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 4, name: "deprecated_field4", kind: "message", T: TestDeprecatedLite, opt: true }, ]); @@ -1230,7 +1230,7 @@ export class TestParsingMergeLite extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestParsingMergeLite"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "required_all_types", kind: "message", T: TestAllTypesLite }, + { no: 1, name: "required_all_types", kind: "message", T: TestAllTypesLite, req: true }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypesLite, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypesLite, repeated: true }, { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMergeLite_OptionalGroup, delimited: true, opt: true }, @@ -1622,7 +1622,7 @@ export class V1MessageLite extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.V1MessageLite"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 2, name: "enum_field", kind: "enum", T: proto2.getEnumType(V1EnumLite), opt: true, default: V1EnumLite.V1_FIRST }, ]); @@ -1665,7 +1665,7 @@ export class V2MessageLite extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.V2MessageLite"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "int_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 2, name: "enum_field", kind: "enum", T: proto2.getEnumType(V2EnumLite), opt: true, default: V2EnumLite.V2_FIRST }, ]); diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts index 6718de10d..a55b8a57e 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts @@ -289,7 +289,7 @@ export class TestMessageSetExtension3 extends Message static readonly typeName = "protobuf_unittest.TestMessageSetExtension3"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ { no: 35, name: "msg", kind: "message", T: NestedTestInt, opt: true }, - { no: 36, name: "required_int", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 36, name: "required_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestMessageSetExtension3 { @@ -379,8 +379,8 @@ export class RawMessageSet_Item extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.RawMessageSet.Item"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 2, name: "type_id", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 3, name: "message", kind: "scalar", T: 12 /* ScalarType.BYTES */ }, + { no: 2, name: "type_id", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, + { no: 3, name: "message", kind: "scalar", T: 12 /* ScalarType.BYTES */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): RawMessageSet_Item { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_optimize_for_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_optimize_for_pb.ts index 840e2de5e..542075c23 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_optimize_for_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_optimize_for_pb.ts @@ -123,7 +123,7 @@ export class TestRequiredOptimizedForSize extends Message [ - { no: 1, name: "x", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "x", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestRequiredOptimizedForSize { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts index dea7e4e08..ba1a5abf5 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts @@ -2401,7 +2401,7 @@ export class TestRequiredEnum extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestRequiredEnum"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(ForeignEnum) }, + { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(ForeignEnum), req: true }, { no: 2, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, ]); @@ -2448,7 +2448,7 @@ export class TestRequiredEnumNoMask extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestRequiredEnumNoMask"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(TestRequiredEnumNoMask_NestedEnum) }, + { no: 1, name: "required_enum", kind: "enum", T: proto2.getEnumType(TestRequiredEnumNoMask_NestedEnum), req: true }, { no: 2, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, ]); @@ -2538,10 +2538,10 @@ export class TestRequiredEnumMulti extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestRequiredEnumMulti"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum) }, + { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum), req: true }, { no: 3, name: "a_3", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum) }, - { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum) }, + { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredEnumMulti_NestedEnum), req: true }, + { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum), req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestRequiredEnumMulti { @@ -2644,13 +2644,13 @@ export class TestRequiredNoMaskMulti extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestRequiredNoMaskMulti"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 80, name: "required_fixed32_80", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 70, name: "required_fixed32_70", kind: "scalar", T: 7 /* ScalarType.FIXED32 */ }, - { no: 64, name: "required_enum_64", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum) }, - { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum) }, + { no: 80, name: "required_fixed32_80", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 70, name: "required_fixed32_70", kind: "scalar", T: 7 /* ScalarType.FIXED32 */, req: true }, + { no: 64, name: "required_enum_64", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum), req: true }, + { no: 4, name: "required_enum_4", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum), req: true }, { no: 3, name: "a_3", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum) }, - { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum) }, + { no: 2, name: "required_enum_2", kind: "enum", T: proto2.getEnumType(TestRequiredNoMaskMulti_NestedEnum), req: true }, + { no: 1, name: "required_enum_1", kind: "enum", T: proto2.getEnumType(ForeignEnum), req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestRequiredNoMaskMulti { @@ -2895,9 +2895,9 @@ export class TestRequired extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestRequired"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 2, name: "dummy2", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 3, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 3, name: "b", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 4, name: "dummy4", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 5, name: "dummy5", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 6, name: "dummy6", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, @@ -2927,7 +2927,7 @@ export class TestRequired extends Message { { no: 30, name: "dummy30", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 31, name: "dummy31", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 32, name: "dummy32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 33, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 33, name: "c", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, { no: 34, name: "optional_foreign", kind: "message", T: ForeignMessage, opt: true }, ]); @@ -3052,7 +3052,7 @@ export class TestRequiredMessage extends Message { static readonly fields: FieldList = proto2.util.newFieldList(() => [ { no: 1, name: "optional_message", kind: "message", T: TestRequired, opt: true }, { no: 2, name: "repeated_message", kind: "message", T: TestRequired, repeated: true }, - { no: 3, name: "required_message", kind: "message", T: TestRequired }, + { no: 3, name: "required_message", kind: "message", T: TestRequired, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestRequiredMessage { @@ -3786,7 +3786,7 @@ export class TestIsInitialized_SubMessage_SubGroup extends Message [ - { no: 2, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 2, name: "i", kind: "scalar", T: 5 /* ScalarType.INT32 */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestIsInitialized_SubMessage_SubGroup { @@ -5969,7 +5969,7 @@ export class TestRequiredOneof_NestedMessage extends Message [ - { no: 1, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */ }, + { no: 1, name: "required_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestRequiredOneof_NestedMessage { @@ -6596,7 +6596,7 @@ export class TestParsingMerge extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestParsingMerge"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "required_all_types", kind: "message", T: TestAllTypes }, + { no: 1, name: "required_all_types", kind: "message", T: TestAllTypes, req: true }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypes, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypes, repeated: true }, { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMerge_OptionalGroup, delimited: true, opt: true }, diff --git a/packages/protobuf-test/src/msg-maps.test.ts b/packages/protobuf-test/src/msg-maps.test.ts index 241d67aed..adc169587 100644 --- a/packages/protobuf-test/src/msg-maps.test.ts +++ b/packages/protobuf-test/src/msg-maps.test.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { expect, test } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; import type { JsonValue, PlainMessage } from "@bufbuild/protobuf"; import { describeMT } from "./helpers.js"; import { MapsMessage as TS_MapsMessage } from "./gen/ts/extra/msg-maps_pb.js"; @@ -122,4 +122,25 @@ describeMT({ ts: TS_MapsMessage, js: JS_MapsMessage }, (messageType) => { }, }); }); + describe("field info", () => { + test.each(messageType.fields.byNumber())("$name", (field) => { + expect(typeof field.no).toBe("number"); + expect(typeof field.name).toBe("string"); + expect(typeof field.localName).toBe("string"); + expect(typeof field.jsonName).toBe("string"); + expect(field.repeated).toBe(false); + expect(field.packed).toBe(false); + expect(field.delimited).toBe(false); + expect(field.oneof).toBeUndefined(); + expect(field.default).toBeUndefined(); + expect(field.opt).toBe(false); + expect(field.req).toBe(false); + expect(field.kind).toBe("map"); + if (field.kind == "map") { + expect(typeof field.K).toBe("number"); + expect(Object.keys(field.V).sort()).toStrictEqual(["T", "kind"]); + expect(typeof field.V.kind).toBe("string"); + } + }); + }); }); diff --git a/packages/protobuf-test/src/msg-message.test.ts b/packages/protobuf-test/src/msg-message.test.ts index 9b14a62b4..4d9e222b5 100644 --- a/packages/protobuf-test/src/msg-message.test.ts +++ b/packages/protobuf-test/src/msg-message.test.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { expect, test } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; import type { JsonValue, PlainMessage } from "@bufbuild/protobuf"; import { MessageFieldMessage as TS_MessageFieldMessage } from "./gen/ts/extra/msg-message_pb.js"; import { MessageFieldMessage as JS_MessageFieldMessage } from "./gen/js/extra/msg-message_pb.js"; @@ -102,5 +102,36 @@ describeMT( }), ); }); + describe("field info", () => { + test.each(messageType.fields.byNumber())("$name", (field) => { + expect(typeof field.no).toBe("number"); + expect(typeof field.name).toBe("string"); + expect(typeof field.localName).toBe("string"); + expect(typeof field.jsonName).toBe("string"); + expect(field.packed).toBe(false); + expect(field.delimited).toBe(false); + expect(field.oneof).toBeUndefined(); + expect(field.default).toBeUndefined(); + expect(field.opt).toBe(false); + expect(field.req).toBe(false); + expect(field.kind).toBe("message"); + }); + test("message_field", () => { + const f = messageType.fields.find(1); + expect(f?.kind).toBe("message"); + expect(f?.repeated).toBe(false); + if (f?.kind == "message") { + expect(f.T.typeName).toBe("spec.MessageFieldMessage.TestMessage"); + } + }); + test("repeated_message_field", () => { + const f = messageType.fields.find(2); + expect(f?.repeated).toBe(true); + expect(f?.kind).toBe("message"); + if (f?.kind == "message") { + expect(f.T.typeName).toBe("spec.MessageFieldMessage.TestMessage"); + } + }); + }); }, ); diff --git a/packages/protobuf-test/src/msg-oneof.test.ts b/packages/protobuf-test/src/msg-oneof.test.ts index 251f4190e..cadeb1a5d 100644 --- a/packages/protobuf-test/src/msg-oneof.test.ts +++ b/packages/protobuf-test/src/msg-oneof.test.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { expect, test } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; import type { JsonValue, PlainMessage } from "@bufbuild/protobuf"; import { describeMT } from "./helpers.js"; import { OneofMessage as TS_OneofMessage } from "./gen/ts/extra/msg-oneof_pb.js"; @@ -78,4 +78,44 @@ describeMT({ ts: TS_OneofMessage, js: JS_OneofMessage }, (messageType) => { scalar: { case: "bytes", value: new Uint8Array(bytes) }, }); }); + describe("field info", () => { + test.each(messageType.fields.byNumber())("$name", (field) => { + expect(typeof field.no).toBe("number"); + expect(typeof field.name).toBe("string"); + expect(typeof field.localName).toBe("string"); + expect(typeof field.jsonName).toBe("string"); + expect(field.repeated).toBe(false); + expect(typeof field.packed).toBe("boolean"); + expect(field.delimited).toBe(false); + expect(field.default).toBeUndefined(); + expect(field.opt).toBe(false); + expect(field.req).toBe(false); + }); + test.each(["value", "error", "bytes"])("oneof scalar %s", (fieldName) => { + const f = messageType.fields.findJsonName(fieldName); + expect(f?.oneof?.name).toBe("scalar"); + expect(f?.kind).toBe("scalar"); + if (f?.kind == "scalar") { + expect(typeof f.T).toBe("number"); + expect(typeof f.L).toBe("number"); + expect(typeof f.packed).toBe("boolean"); + } + }); + test.each(["foo", "bar", "baz"])("oneof message %s", (fieldName) => { + const f = messageType.fields.findJsonName(fieldName); + expect(f?.oneof?.name).toBe("message"); + expect(f?.kind).toBe("message"); + if (f?.kind == "message") { + expect(typeof f.T.typeName).toBe("string"); + } + }); + test.each(["e"])("oneof enum %s", (fieldName) => { + const f = messageType.fields.findJsonName(fieldName); + expect(f?.oneof?.name).toBe("enum"); + expect(f?.kind).toBe("enum"); + if (f?.kind == "enum") { + expect(f.T.typeName).toBe("spec.OneofEnum"); + } + }); + }); }); diff --git a/packages/protobuf-test/src/msg-scalar.test.ts b/packages/protobuf-test/src/msg-scalar.test.ts index a034449ec..e3796be06 100644 --- a/packages/protobuf-test/src/msg-scalar.test.ts +++ b/packages/protobuf-test/src/msg-scalar.test.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { expect, test } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; import { RepeatedScalarValuesMessage as TS_RepeatedScalarValuesMessage, ScalarValuesMessage as TS_ScalarValuesMessage, @@ -22,8 +22,8 @@ import { ScalarValuesMessage as JS_ScalarValuesMessage, } from "./gen/js/extra/msg-scalar_pb.js"; import type { JsonValue, PlainMessage } from "@bufbuild/protobuf"; +import { protoInt64, ScalarType } from "@bufbuild/protobuf"; import { describeMT } from "./helpers.js"; -import { protoInt64 } from "@bufbuild/protobuf"; describeMT( { ts: TS_ScalarValuesMessage, js: JS_ScalarValuesMessage }, @@ -119,6 +119,26 @@ describeMT( bytesField: new Uint8Array(bytes), }); }); + describe("field info", () => { + test.each(messageType.fields.byNumber())("$name", (field) => { + expect(typeof field.no).toBe("number"); + expect(typeof field.name).toBe("string"); + expect(typeof field.localName).toBe("string"); + expect(typeof field.jsonName).toBe("string"); + expect(field.repeated).toBe(false); + expect(field.delimited).toBe(false); + expect(typeof field.packed).toBe("boolean"); + expect(field.oneof).toBeUndefined(); + expect(field.default).toBeUndefined(); + expect(field.opt).toBe(false); + expect(field.req).toBe(false); + expect(field.kind).toBe("scalar"); + if (field.kind == "scalar") { + expect(typeof field.T).toBe("number"); + expect(typeof field.L).toBe("number"); + } + }); + }); }, ); @@ -224,5 +244,48 @@ describeMT( bytesField: [new Uint8Array(bytes)], }); }); + describe("field info", () => { + test.each(messageType.fields.byNumber())("$name", (field) => { + expect(typeof field.no).toBe("number"); + expect(typeof field.name).toBe("string"); + expect(typeof field.localName).toBe("string"); + expect(typeof field.jsonName).toBe("string"); + expect(field.repeated).toBe(true); + expect(field.delimited).toBeFalsy(); + expect(field.oneof).toBeUndefined(); + expect(field.default).toBeUndefined(); + expect(field.opt).toBeFalsy(); + expect(field.kind).toBe("scalar"); + if (field.kind == "scalar") { + expect(typeof field.T).toBe("number"); + expect(typeof field.L).toBe("number"); + expect(field.packed).toBe( + field.T !== ScalarType.STRING && field.T !== ScalarType.BYTES, + ); + } + }); + }); + describe("field info", () => { + test.each(messageType.fields.byNumber())("$name", (field) => { + expect(typeof field.no).toBe("number"); + expect(typeof field.name).toBe("string"); + expect(typeof field.localName).toBe("string"); + expect(typeof field.jsonName).toBe("string"); + expect(field.repeated).toBe(true); + expect(field.delimited).toBe(false); + expect(field.oneof).toBeUndefined(); + expect(field.default).toBeUndefined(); + expect(field.opt).toBe(false); + expect(field.req).toBe(false); + expect(field.kind).toBe("scalar"); + if (field.kind == "scalar") { + expect(typeof field.T).toBe("number"); + expect(typeof field.L).toBe("number"); + expect(field.packed).toBe( + field.T !== ScalarType.STRING && field.T !== ScalarType.BYTES, + ); + } + }); + }); }, ); diff --git a/packages/protobuf-test/src/proto2.test.ts b/packages/protobuf-test/src/proto2.test.ts index fe8b5fc92..762032e7c 100644 --- a/packages/protobuf-test/src/proto2.test.ts +++ b/packages/protobuf-test/src/proto2.test.ts @@ -36,7 +36,8 @@ function verify(m: T): boolean { return m .getType() .fields.list() - .every((f) => f.opt || (m as AnyMessage)[f.localName] !== undefined); + .filter((f) => f.req) + .every((f) => (m as AnyMessage)[f.localName] !== undefined); } describe("setDefaults", () => { @@ -78,6 +79,112 @@ describe("verify", () => { ); }); +describe("proto2 field info packed", () => { + describeMT( + { ts: TS.Proto2PackedMessage, js: JS.Proto2PackedMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is packed", (field) => { + expect(field.packed).toBe(true); + expect(field.repeated).toBe(true); + }); + }, + ); + describeMT( + { ts: TS.Proto2UnpackedMessage, js: JS.Proto2UnpackedMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is unpacked", (field) => { + expect(field.packed).toBe(false); + expect(field.repeated).toBe(true); + }); + }, + ); + describeMT( + { + ts: TS.Proto2UnspecifiedPackedMessage, + js: JS.Proto2UnspecifiedPackedMessage, + }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is unpacked", (field) => { + expect(field.packed).toBe(false); + expect(field.repeated).toBe(true); + }); + }, + ); +}); + +describe("proto3 field info optional", () => { + describeMT( + { ts: TS.Proto2RequiredMessage, js: JS.Proto2RequiredMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is required", (field) => { + expect(field.opt).toBeFalsy(); + }); + }, + ); + describeMT( + { ts: TS.Proto2OptionalMessage, js: JS.Proto2OptionalMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is optional", (field) => { + expect(field.opt).toBe(true); + }); + }, + ); +}); + +describe("proto2 field info packed", () => { + describeMT( + { ts: TS.Proto2PackedMessage, js: JS.Proto2PackedMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is packed", (field) => { + expect(field.packed).toBe(true); + expect(field.repeated).toBe(true); + }); + }, + ); + describeMT( + { ts: TS.Proto2UnpackedMessage, js: JS.Proto2UnpackedMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is unpacked", (field) => { + expect(field.packed).toBe(false); + expect(field.repeated).toBe(true); + }); + }, + ); + describeMT( + { + ts: TS.Proto2UnspecifiedPackedMessage, + js: JS.Proto2UnspecifiedPackedMessage, + }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is unpacked", (field) => { + expect(field.packed).toBe(false); + expect(field.repeated).toBe(true); + }); + }, + ); +}); + +describe("proto3 field info optional / required", () => { + describeMT( + { ts: TS.Proto2RequiredMessage, js: JS.Proto2RequiredMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is required", (field) => { + expect(field.req).toBe(true); + expect(field.opt).toBe(false); + }); + }, + ); + describeMT( + { ts: TS.Proto2OptionalMessage, js: JS.Proto2OptionalMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is optional", (field) => { + expect(field.req).toBe(false); + expect(field.opt).toBe(true); + }); + }, + ); +}); + describeMT( { ts: TS.Proto2RequiredMessage, js: JS.Proto2RequiredMessage }, (messageType) => { diff --git a/packages/protobuf-test/src/proto3.test.ts b/packages/protobuf-test/src/proto3.test.ts new file mode 100644 index 000000000..bb09e016d --- /dev/null +++ b/packages/protobuf-test/src/proto3.test.ts @@ -0,0 +1,73 @@ +// Copyright 2021-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { describe, expect, test } from "@jest/globals"; +import * as TS from "./gen/ts/extra/proto3_pb.js"; +import * as JS from "./gen/js/extra/proto3_pb.js"; +import { describeMT } from "./helpers.js"; + +describe("proto3 field info packed", () => { + // Also see msg-scalars.test.ts + describeMT( + { ts: TS.Proto3PackedMessage, js: JS.Proto3PackedMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is packed", (field) => { + expect(field.packed).toBe(true); + expect(field.repeated).toBe(true); + }); + }, + ); + describeMT( + { ts: TS.Proto3UnpackedMessage, js: JS.Proto3UnpackedMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is unpacked", (field) => { + expect(field.packed).toBe(false); + expect(field.repeated).toBe(true); + }); + }, + ); + describeMT( + { + ts: TS.Proto3UnlabelledMessage, + js: JS.Proto3UnlabelledMessage, + }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is unpacked", (field) => { + expect(field.packed).toBe(true); + expect(field.repeated).toBe(true); + }); + }, + ); +}); + +describe("proto3 field info optional / required", () => { + describeMT( + { ts: TS.Proto3OptionalMessage, js: JS.Proto3OptionalMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is optional", (field) => { + expect(field.req).toBe(false); + expect(field.opt).toBe(true); + }); + }, + ); + describeMT( + { ts: TS.Proto3UnlabelledMessage, js: JS.Proto3UnlabelledMessage }, + (messageType) => { + test.each(messageType.fields.byNumber())("$name is optional", (field) => { + expect(field.req).toBe(false); + expect(field.opt).toBe(false); + }); + }, + ); +}); diff --git a/packages/protobuf/src/create-registry-from-desc.ts b/packages/protobuf/src/create-registry-from-desc.ts index 375c1d475..542325b80 100644 --- a/packages/protobuf/src/create-registry-from-desc.ts +++ b/packages/protobuf/src/create-registry-from-desc.ts @@ -16,8 +16,8 @@ import { assert } from "./private/assert.js"; import type { MessageType } from "./message-type.js"; import { proto3 } from "./proto3.js"; import { proto2 } from "./proto2.js"; -import type { PartialFieldInfo } from "./field.js"; -import { LongType } from "./field.js"; +import type { FieldInfo } from "./field.js"; +import { ScalarType } from "./field.js"; import type { EnumType, EnumValueInfo } from "./enum.js"; import type { IEnumTypeRegistry, @@ -51,12 +51,16 @@ import { UInt64Value, } from "./google/protobuf/wrappers_pb.js"; import { + FieldDescriptorProto_Label, FieldDescriptorProto_Type, FileDescriptorSet, } from "./google/protobuf/descriptor_pb.js"; import type { + AnyDesc, + DescEnum, DescExtension, DescField, + DescMessage, DescriptorSet, } from "./descriptor-set.js"; import { createDescriptorSet } from "./create-descriptor-set.js"; @@ -165,14 +169,13 @@ export function createRegistryFromDescriptors( return undefined; } const runtime = desc.file.syntax == "proto3" ? proto3 : proto2; - const fields: PartialFieldInfo[] = []; + const fields: FieldInfo[] = []; const type = runtime.makeMessageType(typeName, () => fields, { localName: localName(desc), }); messages.set(typeName, type); for (const field of desc.fields) { - const fieldInfo = makeFieldInfo(field, this); - fields.push(fieldInfo); + fields.push(makeFieldInfo(field, this)); } return type; }, @@ -191,20 +194,8 @@ export function createRegistryFromDescriptors( } const methods: Record = {}; for (const method of desc.methods) { - const I = this.findMessage(method.input.typeName); - const O = this.findMessage(method.output.typeName); - assert( - I, - `message "${ - method.input.typeName - }" for ${method.toString()} not found`, - ); - assert( - O, - `output message "${ - method.output.typeName - }" for ${method.toString()} not found`, - ); + const I = resolve(method.input, this, method); + const O = resolve(method.output, this, method); methods[localName(method)] = { name: method.name, I, @@ -255,11 +246,7 @@ export function createRegistryFromDescriptors( if (!desc) { return undefined; } - const extendee = this.findMessage(desc.extendee.typeName); - assert( - extendee, - `message "${desc.extendee.typeName}" for ${desc.toString()} not found`, - ); + const extendee = resolve(desc.extendee, this, desc); const runtime = desc.file.syntax == "proto3" ? proto3 : proto2; const ext = runtime.makeExtension( typeName, @@ -272,199 +259,85 @@ export function createRegistryFromDescriptors( }; } -interface Resolver extends IMessageTypeRegistry, IEnumTypeRegistry {} - function makeFieldInfo( desc: DescField | DescExtension, - resolver: Resolver, -): PartialFieldInfo { + registry: IMessageTypeRegistry & IEnumTypeRegistry, +): FieldInfo { + const f = { + kind: desc.fieldKind, + no: desc.number, + name: desc.name, + jsonName: desc.jsonName, + delimited: desc.proto.type == FieldDescriptorProto_Type.GROUP, + repeated: desc.repeated, + packed: desc.packed, + oneof: desc.oneof?.name, + opt: desc.optional, + req: desc.proto.label === FieldDescriptorProto_Label.REQUIRED, + } as Record; + switch (desc.fieldKind) { - case "map": + case "map": { assert(desc.kind == "field"); // maps are not allowed for extensions - return makeMapFieldInfo(desc, resolver); - case "message": - return makeMessageFieldInfo(desc, resolver); + let T: EnumType | MessageType | ScalarType | undefined; + switch (desc.mapValue.kind) { + case "scalar": + T = desc.mapValue.scalar; + break; + case "enum": { + T = resolve(desc.mapValue.enum, registry, desc); + break; + } + case "message": { + T = resolve(desc.mapValue.message, registry, desc); + break; + } + } + f.K = desc.mapKey; + f.V = { + kind: desc.mapValue.kind, + T, + }; + break; + } + case "message": { + f.T = resolve(desc.message, registry, desc); + break; + } case "enum": { - const fi = makeEnumFieldInfo(desc, resolver); - fi.default = desc.getDefaultValue(); - return fi; + f.T = resolve(desc.enum, registry, desc); + f.default = desc.getDefaultValue(); + break; } case "scalar": { - const fi = makeScalarFieldInfo(desc); - fi.default = desc.getDefaultValue(); - return fi; + f.L = desc.longType; + f.T = desc.scalar; + f.default = desc.getDefaultValue(); + break; } } + return f as FieldInfo; } -function makeMapFieldInfo( - field: DescField & { fieldKind: "map" }, - resolver: Resolver, -): PartialFieldInfo { - const base = { - kind: "map", - no: field.number, - name: field.name, - jsonName: field.jsonName, - K: field.mapKey, - } as const; - if (field.mapValue.message) { - const messageType = resolver.findMessage(field.mapValue.message.typeName); - assert( - messageType, - `message "${ - field.mapValue.message.typeName - }" for ${field.toString()} not found`, - ); - return { - ...base, - V: { - kind: "message", - T: messageType, - }, - }; - } - if (field.mapValue.enum) { - const enumType = resolver.findEnum(field.mapValue.enum.typeName); - assert( - enumType, - `enum "${ - field.mapValue.enum.typeName - }" for ${field.toString()} not found`, - ); - return { - ...base, - V: { - kind: "enum", - T: enumType, - }, - }; - } - return { - ...base, - V: { - kind: "scalar", - T: field.mapValue.scalar, - }, - }; -} - -function makeScalarFieldInfo( - field: (DescField | DescExtension) & { fieldKind: "scalar" }, -): PartialFieldInfo { - // We are creating _partial_ field info here, so we omit long type bigint, - // which is the default. - const longType = - field.longType == LongType.STRING - ? ({ L: LongType.STRING } as const) - : ({} as const); - const base = { - kind: "scalar", - no: field.number, - name: field.name, - jsonName: field.jsonName, - T: field.scalar, - ...longType, - } as const; - if (field.repeated) { - return { - ...base, - repeated: true, - packed: field.packed, - oneof: undefined, - T: field.scalar, - }; - } - if (field.oneof) { - return { - ...base, - oneof: field.oneof.name, - }; - } - if (field.optional) { - return { - ...base, - opt: true, - }; - } - return base; -} - -function makeMessageFieldInfo( - field: (DescField | DescExtension) & { fieldKind: "message" }, - resolver: Resolver, -): PartialFieldInfo { - const messageType = resolver.findMessage(field.message.typeName); - assert( - messageType, - `message "${field.message.typeName}" for ${field.toString()} not found`, - ); - const base = { - kind: "message", - no: field.number, - name: field.name, - jsonName: field.jsonName, - T: messageType, - delimited: field.proto.type == FieldDescriptorProto_Type.GROUP, - } as const; - if (field.repeated) { - return { - ...base, - repeated: true, - packed: field.packed, - oneof: undefined, - }; - } - if (field.oneof) { - return { - ...base, - oneof: field.oneof.name, - }; - } - if (field.optional) { - return { - ...base, - opt: true, - }; - } - return base; -} - -function makeEnumFieldInfo( - field: (DescField | DescExtension) & { fieldKind: "enum" }, - resolver: Resolver, -): PartialFieldInfo { - const enumType = resolver.findEnum(field.enum.typeName); - assert( - enumType, - `enum "${field.enum.typeName}" for ${field.toString()} not found`, - ); - const base = { - kind: "enum", - no: field.number, - name: field.name, - jsonName: field.jsonName, - T: enumType, - } as const; - if (field.repeated) { - return { - ...base, - repeated: true, - packed: field.packed, - oneof: undefined, - }; - } - if (field.oneof) { - return { - ...base, - oneof: field.oneof.name, - }; - } - if (field.optional) { - return { - ...base, - opt: true, - }; - } - return base; +function resolve( + desc: DescMessage, + registry: IMessageTypeRegistry & IEnumTypeRegistry, + context: AnyDesc, +): MessageType; +function resolve( + desc: DescEnum, + registry: IMessageTypeRegistry & IEnumTypeRegistry, + context: AnyDesc, +): EnumType; +function resolve( + desc: DescMessage | DescEnum, + registry: IMessageTypeRegistry & IEnumTypeRegistry, + context: AnyDesc, +): MessageType | EnumType { + const type = + desc.kind == "message" + ? registry.findMessage(desc.typeName) + : registry.findEnum(desc.typeName); + assert(type, `${desc.toString()}" for ${context.toString()} not found`); + return type; } diff --git a/packages/protobuf/src/field.ts b/packages/protobuf/src/field.ts index fbdf252e2..0057abb7b 100644 --- a/packages/protobuf/src/field.ts +++ b/packages/protobuf/src/field.ts @@ -33,6 +33,7 @@ import type { MessageType } from "./message-type.js"; * - "localName": The name of the field as used in generated code. * - "jsonName": The name for JSON serialization / deserialization. * - "opt": Whether the field is optional. + * - "req": Whether the field is required (a legacy proto2 feature). * - "repeated": Whether the field is repeated. * - "packed": Whether the repeated field is packed. * @@ -73,6 +74,7 @@ export interface OneofInfo { readonly repeated: false; readonly packed: false; readonly opt: false; + readonly req: false; readonly default: undefined; readonly delimited?: undefined; readonly fields: readonly FieldInfo[]; @@ -160,6 +162,11 @@ interface fiScalar extends fiShared { */ readonly opt: boolean; + /** + * Is the field required? A legacy proto2 feature. + */ + readonly req: boolean; + /** * Only proto2: An explicit default value. */ @@ -192,6 +199,11 @@ interface fiMessage extends fiShared { */ readonly packed: false; + /** + * Is the field required? A legacy proto2 feature. + */ + readonly req: boolean; + /** * An explicit default value (only proto2). Never set for messages. */ @@ -231,6 +243,11 @@ interface fiEnum extends fiShared { */ readonly opt: boolean; + /** + * Is the field required? A legacy proto2 feature. + */ + readonly req: boolean; + /** * Only proto2: An explicit default value. */ @@ -293,18 +310,18 @@ interface fiMap extends fiShared { } // prettier-ignore -type fiRules = Omit & ( - | { readonly repeated: false, readonly packed: false, readonly opt: false; readonly oneof: undefined; } - | { readonly repeated: false, readonly packed: false, readonly opt: true; readonly oneof: undefined; } - | { readonly repeated: boolean, readonly packed: boolean, readonly opt: false; readonly oneof: undefined; } - | { readonly repeated: false, readonly packed: false, readonly opt: false; readonly oneof: OneofInfo; }); +type fiRules = Omit & ( + | { readonly repeated: false, readonly packed: false, readonly opt: false; readonly req: boolean; readonly oneof: undefined; } + | { readonly repeated: false, readonly packed: false, readonly opt: true; readonly req: false; readonly oneof: undefined; } + | { readonly repeated: boolean, readonly packed: boolean, readonly opt: false; readonly req: boolean; readonly oneof: undefined; } + | { readonly repeated: false, readonly packed: false, readonly opt: false; readonly req: false; readonly oneof: OneofInfo; }); // prettier-ignore -type fiPartialRules = Omit & ( - | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } - | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt: true; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } - | { readonly jsonName?: string; readonly repeated?: boolean; readonly packed?: boolean; readonly opt?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } - | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly oneof: string; default?: T["default"]; L?: LongType; delimited?: boolean; }); +type fiPartialRules = Omit & ( + | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly req?: boolean; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } + | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt: true; readonly req?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } + | { readonly jsonName?: string; readonly repeated?: boolean; readonly packed?: boolean; readonly opt?: false; readonly req?: boolean; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } + | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly req?: false; readonly oneof: string; default?: T["default"]; L?: LongType; delimited?: boolean; }); /** * Scalar value types. This is a subset of field types declared by protobuf diff --git a/packages/protobuf/src/google/protobuf/descriptor_pb.ts b/packages/protobuf/src/google/protobuf/descriptor_pb.ts index fe120920e..d92fbee67 100644 --- a/packages/protobuf/src/google/protobuf/descriptor_pb.ts +++ b/packages/protobuf/src/google/protobuf/descriptor_pb.ts @@ -2601,8 +2601,8 @@ export class UninterpretedOption_NamePart extends Message [ - { no: 1, name: "name_part", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "is_extension", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, + { no: 1, name: "name_part", kind: "scalar", T: 9 /* ScalarType.STRING */, req: true }, + { no: 2, name: "is_extension", kind: "scalar", T: 8 /* ScalarType.BOOL */, req: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): UninterpretedOption_NamePart { diff --git a/packages/protobuf/src/private/field-normalize.ts b/packages/protobuf/src/private/field-normalize.ts new file mode 100644 index 000000000..3bf2927f5 --- /dev/null +++ b/packages/protobuf/src/private/field-normalize.ts @@ -0,0 +1,71 @@ +// Copyright 2021-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import type { FieldListSource } from "./field-list.js"; +import type { FieldInfo } from "../field.js"; +import { LongType, ScalarType } from "../field.js"; +import { InternalOneofInfo } from "./field.js"; +import { fieldJsonName, localFieldName } from "./names.js"; + +/** + * Convert a collection of field info to an array of normalized FieldInfo. + * + * The argument `packedByDefault` specifies whether fields that do not specify + * `packed` should be packed (proto3) or unpacked (proto2). + */ +export function normalizeFieldInfos( + fieldInfos: FieldListSource, + packedByDefault: boolean, +): FieldInfo[] { + const r: FieldInfo[] = []; + let o: InternalOneofInfo | undefined; + for (const field of typeof fieldInfos == "function" + ? fieldInfos() + : fieldInfos) { + const f = field as Record; + f.localName = localFieldName(field.name, field.oneof !== undefined); + f.jsonName = field.jsonName ?? fieldJsonName(field.name); + f.repeated = field.repeated ?? false; + if (field.kind == "scalar") { + f.L = field.L ?? LongType.BIGINT; + } + f.delimited = field.delimited ?? false; + f.req = field.req ?? false; + f.opt = field.opt ?? false; + if (field.packed === undefined) { + if (packedByDefault) { + f.packed = + field.kind == "enum" || + (field.kind == "scalar" && + field.T != ScalarType.BYTES && + field.T != ScalarType.STRING); + } else { + f.packed = false; + } + } + // We do not surface options at this time + // f.options = field.options ?? emptyReadonlyObject; + if (field.oneof !== undefined) { + const ooname = + typeof field.oneof == "string" ? field.oneof : field.oneof.name; + if (!o || o.name != ooname) { + o = new InternalOneofInfo(ooname); + } + f.oneof = o; + o.addField(f as FieldInfo); + } + r.push(f as FieldInfo); + } + return r; +} diff --git a/packages/protobuf/src/private/field.ts b/packages/protobuf/src/private/field.ts index a14d2f58b..3821c2dbd 100644 --- a/packages/protobuf/src/private/field.ts +++ b/packages/protobuf/src/private/field.ts @@ -23,6 +23,7 @@ export class InternalOneofInfo implements OneofInfo { readonly repeated = false; readonly packed = false; readonly opt = false; + readonly req = false; readonly default = undefined; readonly fields: FieldInfo[] = []; private _lookup?: { [localName: string]: FieldInfo | undefined }; diff --git a/packages/protobuf/src/proto2.ts b/packages/protobuf/src/proto2.ts index 7b0a5e2a3..79dd7902e 100644 --- a/packages/protobuf/src/proto2.ts +++ b/packages/protobuf/src/proto2.ts @@ -15,15 +15,12 @@ import { makeProtoRuntime } from "./private/proto-runtime.js"; import { makeBinaryFormatProto2 } from "./private/binary-format-proto2.js"; import { makeUtilCommon } from "./private/util-common.js"; -import { InternalFieldList } from "./private/field-list.js"; import type { FieldListSource } from "./private/field-list.js"; +import { InternalFieldList } from "./private/field-list.js"; import type { FieldList } from "./field-list.js"; import type { AnyMessage, Message } from "./message.js"; -import type { FieldInfo } from "./field.js"; -import { InternalOneofInfo } from "./private/field.js"; -import { localFieldName, fieldJsonName } from "./private/names.js"; import { makeJsonFormatProto2 } from "./private/json-format-proto2.js"; -import { LongType } from "./field.js"; +import { normalizeFieldInfos } from "./private/field-normalize.js"; /** * Provides functionality for messages defined with the proto2 syntax. @@ -35,7 +32,9 @@ export const proto2 = makeProtoRuntime( { ...makeUtilCommon(), newFieldList(fields: FieldListSource): FieldList { - return new InternalFieldList(fields, normalizeFieldInfosProto2); + return new InternalFieldList(fields, (source) => + normalizeFieldInfos(source, false), + ); }, initFields(target: Message): void { for (const member of target.getType().fields.byMember()) { @@ -67,40 +66,3 @@ export const proto2 = makeProtoRuntime( }, }, ); - -/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */ - -function normalizeFieldInfosProto2(fieldInfos: FieldListSource): FieldInfo[] { - const r: FieldInfo[] = []; - let o: InternalOneofInfo | undefined; - for (const field of typeof fieldInfos == "function" - ? fieldInfos() - : fieldInfos) { - const f = field as any; - f.localName = localFieldName(field.name, field.oneof !== undefined); - f.jsonName = field.jsonName ?? fieldJsonName(field.name); - f.repeated = field.repeated ?? false; - if (field.kind == "scalar") { - f.L = field.L ?? LongType.BIGINT; - } - // We do not surface options at this time - // f.options = field.options ?? emptyReadonlyObject; - if (field.oneof !== undefined) { - const ooname = - typeof field.oneof == "string" ? field.oneof : field.oneof.name; - if (!o || o.name != ooname) { - o = new InternalOneofInfo(ooname); - } - f.oneof = o; - o.addField(f); - } - // proto2 specific: - if (field.kind == "message") { - f.delimited = field.delimited ?? false; - } - // In contrast to proto3, repeated fields are unpacked except when explicitly specified. - f.packed = field.packed ?? false; - r.push(f); - } - return r; -} diff --git a/packages/protobuf/src/proto3.ts b/packages/protobuf/src/proto3.ts index 702df05ae..9519d2e22 100644 --- a/packages/protobuf/src/proto3.ts +++ b/packages/protobuf/src/proto3.ts @@ -16,15 +16,12 @@ import { makeProtoRuntime } from "./private/proto-runtime.js"; import { makeBinaryFormatProto3 } from "./private/binary-format-proto3.js"; import { makeJsonFormatProto3 } from "./private/json-format-proto3.js"; import { makeUtilCommon } from "./private/util-common.js"; -import { InternalFieldList } from "./private/field-list.js"; import type { FieldListSource } from "./private/field-list.js"; +import { InternalFieldList } from "./private/field-list.js"; import type { FieldList } from "./field-list.js"; import type { AnyMessage, Message } from "./message.js"; import { scalarDefaultValue } from "./private/scalars.js"; -import { LongType, ScalarType } from "./field.js"; -import type { FieldInfo } from "./field.js"; -import { InternalOneofInfo } from "./private/field.js"; -import { localFieldName, fieldJsonName } from "./private/names.js"; +import { normalizeFieldInfos } from "./private/field-normalize.js"; /** * Provides functionality for messages defined with the proto3 syntax. @@ -36,7 +33,9 @@ export const proto3 = makeProtoRuntime( { ...makeUtilCommon(), newFieldList(fields: FieldListSource): FieldList { - return new InternalFieldList(fields, normalizeFieldInfosProto3); + return new InternalFieldList(fields, (source) => + normalizeFieldInfos(source, true), + ); }, initFields(target: Message): void { for (const member of target.getType().fields.byMember()) { @@ -70,50 +69,3 @@ export const proto3 = makeProtoRuntime( }, }, ); - -/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */ - -function normalizeFieldInfosProto3(fieldInfos: FieldListSource): FieldInfo[] { - const r: FieldInfo[] = []; - let o: InternalOneofInfo | undefined; - for (const field of typeof fieldInfos == "function" - ? fieldInfos() - : fieldInfos) { - const f = field as any; - f.localName = localFieldName(field.name, field.oneof !== undefined); - f.jsonName = field.jsonName ?? fieldJsonName(field.name); - f.repeated = field.repeated ?? false; - if (field.kind == "scalar") { - f.L = field.L ?? LongType.BIGINT; - } - // We do not surface options at this time - // f.options = field.options ?? emptyReadonlyObject; - if (field.oneof !== undefined) { - const ooname = - typeof field.oneof == "string" ? field.oneof : field.oneof.name; - if (!o || o.name != ooname) { - o = new InternalOneofInfo(ooname); - } - f.oneof = o; - o.addField(f); - } - // proto3 specific: - if (field.kind == "message") { - f.delimited = false; - } - // From the proto3 language guide: - // > In proto3, repeated fields of scalar numeric types are packed by default. - // This information is incomplete - according to the conformance tests, BOOL - // and ENUM are packed by default as well. This means only STRING and BYTES - // are not packed by default, which makes sense because they are length-delimited. - f.packed = - field.packed ?? - (field.kind == "enum" || - (field.kind == "scalar" && - field.T != ScalarType.BYTES && - field.T != ScalarType.STRING)); - - r.push(f); - } - return r; -} diff --git a/packages/protoc-gen-es/src/javascript.ts b/packages/protoc-gen-es/src/javascript.ts index 03d6b9c7b..290de831d 100644 --- a/packages/protoc-gen-es/src/javascript.ts +++ b/packages/protoc-gen-es/src/javascript.ts @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -import type { +import { DescEnum, DescExtension, DescField, DescMessage, + FieldDescriptorProto_Label, } from "@bufbuild/protobuf"; import { FieldDescriptorProto_Type, @@ -168,6 +169,8 @@ export function getFieldInfoLiteral(schema: Schema, field: DescField | DescExten } if (field.optional) { e.push(`opt: true, `); + } else if (field.proto.label === FieldDescriptorProto_Label.REQUIRED) { + e.push(`req: true, `); } const defaultValue = getFieldExplicitDefaultValue(field, schema.runtime.protoInt64); if (defaultValue !== undefined) {