@bufbuild/protobuf 1.9.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ Some additional features that set it apart from the others:
15
15
  - ECMAScript module support
16
16
  - First-class TypeScript support
17
17
  - Generation of idiomatic JavaScript and TypeScript code.
18
- - Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/blob/main/packages/protobuf-bench)
18
+ - Generation of [much smaller bundles](https://github.com/bufbuild/protobuf-es/blob/main/packages/bundle-size)
19
19
  - Implementation of all proto3 features, including the [canonical JSON format](https://developers.google.com/protocol-buffers/docs/proto3#json).
20
20
  - Implementation of all proto2 features, except for extensions and the text format.
21
21
  - Usage of standard JavaScript APIs instead of the [Closure Library](http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html)
@@ -61,7 +61,7 @@ export interface IBinaryReader {
61
61
  /**
62
62
  * Skip one element on the wire and return the skipped data.
63
63
  */
64
- skip(wireType: WireType): Uint8Array;
64
+ skip(wireType: WireType, fieldNo?: number): Uint8Array;
65
65
  /**
66
66
  * Read a `uint32` field, an unsigned 32 bit varint.
67
67
  */
@@ -347,10 +347,12 @@ export declare class BinaryReader implements IBinaryReader {
347
347
  */
348
348
  tag(): [number, WireType];
349
349
  /**
350
- * Skip one element on the wire and return the skipped data.
351
- * Supports WireType.StartGroup since v2.0.0-alpha.23.
350
+ * Skip one element and return the skipped data.
351
+ *
352
+ * When skipping StartGroup, provide the tags field number to check for
353
+ * matching field number in the EndGroup tag.
352
354
  */
353
- skip(wireType: WireType): Uint8Array;
355
+ skip(wireType: WireType, fieldNo?: number): Uint8Array;
354
356
  protected varint64: () => [number, number];
355
357
  /**
356
358
  * Throws error if position in byte array is out of range.
@@ -294,10 +294,12 @@ class BinaryReader {
294
294
  return [fieldNo, wireType];
295
295
  }
296
296
  /**
297
- * Skip one element on the wire and return the skipped data.
298
- * Supports WireType.StartGroup since v2.0.0-alpha.23.
297
+ * Skip one element and return the skipped data.
298
+ *
299
+ * When skipping StartGroup, provide the tags field number to check for
300
+ * matching field number in the EndGroup tag.
299
301
  */
300
- skip(wireType) {
302
+ skip(wireType, fieldNo) {
301
303
  let start = this.pos;
302
304
  switch (wireType) {
303
305
  case WireType.Varint:
@@ -319,10 +321,15 @@ class BinaryReader {
319
321
  this.pos += len;
320
322
  break;
321
323
  case WireType.StartGroup:
322
- // TODO check for matching field numbers in StartGroup / EndGroup tags
323
- let t;
324
- while ((t = this.tag()[1]) !== WireType.EndGroup) {
325
- this.skip(t);
324
+ for (;;) {
325
+ const [fn, wt] = this.tag();
326
+ if (wt === WireType.EndGroup) {
327
+ if (fieldNo !== undefined && fn !== fieldNo) {
328
+ throw new Error("invalid end group tag");
329
+ }
330
+ break;
331
+ }
332
+ this.skip(wt, fn);
326
333
  }
327
334
  break;
328
335
  default:
@@ -1,9 +1,13 @@
1
1
  import type { MessageType } from "./message-type.js";
2
2
  import type { EnumType } from "./enum.js";
3
3
  import type { ServiceType } from "./service-type.js";
4
- import type { IEnumTypeRegistry, IExtensionRegistry, IMessageTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
4
+ import type { IEnumTypeRegistry, IExtensionRegistry, IMessageTypeRegistry, IMutableRegistry, IServiceTypeRegistry } from "./type-registry.js";
5
5
  import type { Extension } from "./extension.js";
6
6
  /**
7
7
  * Create a new registry from the given types.
8
8
  */
9
9
  export declare function createRegistry(...types: Array<MessageType | EnumType | ServiceType | Extension>): IMessageTypeRegistry & IEnumTypeRegistry & IExtensionRegistry & IServiceTypeRegistry;
10
+ /**
11
+ * Create a mutable registry from the given types.
12
+ */
13
+ export declare function createMutableRegistry(...types: Array<MessageType | EnumType | ServiceType | Extension>): IMutableRegistry;
@@ -13,11 +13,20 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createRegistry = void 0;
16
+ exports.createMutableRegistry = exports.createRegistry = void 0;
17
17
  /**
18
18
  * Create a new registry from the given types.
19
19
  */
20
20
  function createRegistry(...types) {
21
+ const mutable = createMutableRegistry(...types);
22
+ delete mutable.add;
23
+ return mutable;
24
+ }
25
+ exports.createRegistry = createRegistry;
26
+ /**
27
+ * Create a mutable registry from the given types.
28
+ */
29
+ function createMutableRegistry(...types) {
21
30
  const messages = {};
22
31
  const enums = {};
23
32
  const services = {};
@@ -41,54 +50,54 @@ function createRegistry(...types) {
41
50
  var _a;
42
51
  return (_a = extensionsByName.get(typeName)) !== null && _a !== void 0 ? _a : undefined;
43
52
  },
44
- };
45
- function addType(type) {
46
- var _a;
47
- if ("fields" in type) {
48
- if (!registry.findMessage(type.typeName)) {
49
- messages[type.typeName] = type;
50
- type.fields.list().forEach(addField);
53
+ add(type) {
54
+ var _a;
55
+ if ("fields" in type) {
56
+ if (!this.findMessage(type.typeName)) {
57
+ messages[type.typeName] = type;
58
+ type.fields.list().forEach(addField);
59
+ }
51
60
  }
52
- }
53
- else if ("methods" in type) {
54
- if (!registry.findService(type.typeName)) {
55
- services[type.typeName] = type;
56
- for (const method of Object.values(type.methods)) {
57
- addType(method.I);
58
- addType(method.O);
61
+ else if ("methods" in type) {
62
+ if (!this.findService(type.typeName)) {
63
+ services[type.typeName] = type;
64
+ for (const method of Object.values(type.methods)) {
65
+ this.add(method.I);
66
+ this.add(method.O);
67
+ }
59
68
  }
60
69
  }
61
- }
62
- else if ("extendee" in type) {
63
- if (!extensionsByName.has(type.typeName)) {
64
- extensionsByName.set(type.typeName, type);
65
- const extendeeName = type.extendee.typeName;
66
- if (!extensionsByExtendee.has(extendeeName)) {
67
- extensionsByExtendee.set(extendeeName, new Map());
70
+ else if ("extendee" in type) {
71
+ if (!extensionsByName.has(type.typeName)) {
72
+ extensionsByName.set(type.typeName, type);
73
+ const extendeeName = type.extendee.typeName;
74
+ if (!extensionsByExtendee.has(extendeeName)) {
75
+ extensionsByExtendee.set(extendeeName, new Map());
76
+ }
77
+ (_a = extensionsByExtendee.get(extendeeName)) === null || _a === void 0 ? void 0 : _a.set(type.field.no, type);
78
+ this.add(type.extendee);
79
+ addField(type.field);
68
80
  }
69
- (_a = extensionsByExtendee.get(extendeeName)) === null || _a === void 0 ? void 0 : _a.set(type.field.no, type);
70
- addType(type.extendee);
71
- addField(type.field);
72
81
  }
73
- }
74
- else {
75
- enums[type.typeName] = type;
76
- }
77
- }
82
+ else {
83
+ enums[type.typeName] = type;
84
+ }
85
+ },
86
+ };
78
87
  function addField(field) {
79
88
  if (field.kind == "message") {
80
- addType(field.T);
89
+ registry.add(field.T);
81
90
  }
82
91
  else if (field.kind == "map" && field.V.kind == "message") {
83
- addType(field.V.T);
92
+ registry.add(field.V.T);
84
93
  }
85
94
  else if (field.kind == "enum") {
86
- addType(field.T);
95
+ registry.add(field.T);
87
96
  }
88
97
  }
89
98
  for (const type of types) {
90
- addType(type);
99
+ registry.add(type);
91
100
  }
92
101
  return registry;
93
102
  }
94
- exports.createRegistry = createRegistry;
103
+ exports.createMutableRegistry = createMutableRegistry;
@@ -74,7 +74,7 @@ function setExtension(message, extension, value, options) {
74
74
  const reader = readOpt.readerFactory(writer.finish());
75
75
  while (reader.pos < reader.len) {
76
76
  const [no, wireType] = reader.tag();
77
- const data = reader.skip(wireType);
77
+ const data = reader.skip(wireType, no);
78
78
  message.getType().runtime.bin.onUnknownField(message, no, wireType, data);
79
79
  }
80
80
  }
@@ -16,6 +16,13 @@ export declare enum Edition {
16
16
  * @generated from enum value: EDITION_UNKNOWN = 0;
17
17
  */
18
18
  EDITION_UNKNOWN = 0,
19
+ /**
20
+ * A placeholder edition for specifying default behaviors *before* a feature
21
+ * was first introduced. This is effectively an "infinite past".
22
+ *
23
+ * @generated from enum value: EDITION_LEGACY = 900;
24
+ */
25
+ EDITION_LEGACY = 900,
19
26
  /**
20
27
  * Legacy syntax "editions". These pre-date editions, but behave much like
21
28
  * distinct editions. These can't be used to specify the edition of proto
@@ -876,12 +883,16 @@ export declare class FileOptions extends Message<FileOptions> {
876
883
  */
877
884
  javaGenerateEqualsAndHash?: boolean;
878
885
  /**
879
- * If set true, then the Java2 code generator will generate code that
880
- * throws an exception whenever an attempt is made to assign a non-UTF-8
881
- * byte sequence to a string field.
882
- * Message reflection will do the same.
883
- * However, an extension field still accepts non-UTF-8 byte sequences.
884
- * This option has no effect on when used with the lite runtime.
886
+ * A proto2 file can set this to true to opt in to UTF-8 checking for Java,
887
+ * which will throw an exception if invalid UTF-8 is parsed from the wire or
888
+ * assigned to a string field.
889
+ *
890
+ * TODO: clarify exactly what kinds of field types this option
891
+ * applies to, and update these docs accordingly.
892
+ *
893
+ * Proto3 files already perform these checks. Setting the option explicitly to
894
+ * false has no effect: it cannot be used to opt proto3 files out of UTF-8
895
+ * checks.
885
896
  *
886
897
  * @generated from field: optional bool java_string_check_utf8 = 27 [default = false];
887
898
  */
@@ -1266,6 +1277,10 @@ export declare class FieldOptions extends Message<FieldOptions> {
1266
1277
  * @generated from field: optional google.protobuf.FeatureSet features = 21;
1267
1278
  */
1268
1279
  features?: FeatureSet;
1280
+ /**
1281
+ * @generated from field: optional google.protobuf.FieldOptions.FeatureSupport feature_support = 22;
1282
+ */
1283
+ featureSupport?: FieldOptions_FeatureSupport;
1269
1284
  /**
1270
1285
  * The parser stores options it doesn't recognize here. See above.
1271
1286
  *
@@ -1424,6 +1439,51 @@ export declare class FieldOptions_EditionDefault extends Message<FieldOptions_Ed
1424
1439
  static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): FieldOptions_EditionDefault;
1425
1440
  static equals(a: FieldOptions_EditionDefault | PlainMessage<FieldOptions_EditionDefault> | undefined, b: FieldOptions_EditionDefault | PlainMessage<FieldOptions_EditionDefault> | undefined): boolean;
1426
1441
  }
1442
+ /**
1443
+ * Information about the support window of a feature.
1444
+ *
1445
+ * @generated from message google.protobuf.FieldOptions.FeatureSupport
1446
+ */
1447
+ export declare class FieldOptions_FeatureSupport extends Message<FieldOptions_FeatureSupport> {
1448
+ /**
1449
+ * The edition that this feature was first available in. In editions
1450
+ * earlier than this one, the default assigned to EDITION_LEGACY will be
1451
+ * used, and proto files will not be able to override it.
1452
+ *
1453
+ * @generated from field: optional google.protobuf.Edition edition_introduced = 1;
1454
+ */
1455
+ editionIntroduced?: Edition;
1456
+ /**
1457
+ * The edition this feature becomes deprecated in. Using this after this
1458
+ * edition may trigger warnings.
1459
+ *
1460
+ * @generated from field: optional google.protobuf.Edition edition_deprecated = 2;
1461
+ */
1462
+ editionDeprecated?: Edition;
1463
+ /**
1464
+ * The deprecation warning text if this feature is used after the edition it
1465
+ * was marked deprecated in.
1466
+ *
1467
+ * @generated from field: optional string deprecation_warning = 3;
1468
+ */
1469
+ deprecationWarning?: string;
1470
+ /**
1471
+ * The edition this feature is no longer available in. In editions after
1472
+ * this one, the last default assigned will be used, and proto files will
1473
+ * not be able to override it.
1474
+ *
1475
+ * @generated from field: optional google.protobuf.Edition edition_removed = 4;
1476
+ */
1477
+ editionRemoved?: Edition;
1478
+ constructor(data?: PartialMessage<FieldOptions_FeatureSupport>);
1479
+ static readonly runtime: typeof proto2;
1480
+ static readonly typeName = "google.protobuf.FieldOptions.FeatureSupport";
1481
+ static readonly fields: FieldList;
1482
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FieldOptions_FeatureSupport;
1483
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): FieldOptions_FeatureSupport;
1484
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): FieldOptions_FeatureSupport;
1485
+ static equals(a: FieldOptions_FeatureSupport | PlainMessage<FieldOptions_FeatureSupport> | undefined, b: FieldOptions_FeatureSupport | PlainMessage<FieldOptions_FeatureSupport> | undefined): boolean;
1486
+ }
1427
1487
  /**
1428
1488
  * @generated from message google.protobuf.OneofOptions
1429
1489
  */
@@ -1529,6 +1589,12 @@ export declare class EnumValueOptions extends Message<EnumValueOptions> {
1529
1589
  * @generated from field: optional bool debug_redact = 3 [default = false];
1530
1590
  */
1531
1591
  debugRedact?: boolean;
1592
+ /**
1593
+ * Information about the support window of a feature value.
1594
+ *
1595
+ * @generated from field: optional google.protobuf.FieldOptions.FeatureSupport feature_support = 4;
1596
+ */
1597
+ featureSupport?: FieldOptions_FeatureSupport;
1532
1598
  /**
1533
1599
  * The parser stores options it doesn't recognize here. See above.
1534
1600
  *
@@ -1919,9 +1985,17 @@ export declare class FeatureSetDefaults_FeatureSetEditionDefault extends Message
1919
1985
  */
1920
1986
  edition?: Edition;
1921
1987
  /**
1922
- * @generated from field: optional google.protobuf.FeatureSet features = 2;
1988
+ * Defaults of features that can be overridden in this edition.
1989
+ *
1990
+ * @generated from field: optional google.protobuf.FeatureSet overridable_features = 4;
1923
1991
  */
1924
- features?: FeatureSet;
1992
+ overridableFeatures?: FeatureSet;
1993
+ /**
1994
+ * Defaults of features that can't be overridden in this edition.
1995
+ *
1996
+ * @generated from field: optional google.protobuf.FeatureSet fixed_features = 5;
1997
+ */
1998
+ fixedFeatures?: FeatureSet;
1925
1999
  constructor(data?: PartialMessage<FeatureSetDefaults_FeatureSetEditionDefault>);
1926
2000
  static readonly runtime: typeof proto2;
1927
2001
  static readonly typeName = "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault";
@@ -13,7 +13,7 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annotation = exports.GeneratedCodeInfo = exports.SourceCodeInfo_Location = exports.SourceCodeInfo = exports.FeatureSetDefaults_FeatureSetEditionDefault = exports.FeatureSetDefaults = exports.FeatureSet_JsonFormat = exports.FeatureSet_MessageEncoding = exports.FeatureSet_Utf8Validation = exports.FeatureSet_RepeatedFieldEncoding = exports.FeatureSet_EnumType = exports.FeatureSet_FieldPresence = exports.FeatureSet = exports.UninterpretedOption_NamePart = exports.UninterpretedOption = exports.MethodOptions_IdempotencyLevel = exports.MethodOptions = exports.ServiceOptions = exports.EnumValueOptions = exports.EnumOptions = exports.OneofOptions = exports.FieldOptions_EditionDefault = exports.FieldOptions_OptionTargetType = exports.FieldOptions_OptionRetention = exports.FieldOptions_JSType = exports.FieldOptions_CType = exports.FieldOptions = exports.MessageOptions = exports.FileOptions_OptimizeMode = exports.FileOptions = exports.MethodDescriptorProto = exports.ServiceDescriptorProto = exports.EnumValueDescriptorProto = exports.EnumDescriptorProto_EnumReservedRange = exports.EnumDescriptorProto = exports.OneofDescriptorProto = exports.FieldDescriptorProto_Label = exports.FieldDescriptorProto_Type = exports.FieldDescriptorProto = exports.ExtensionRangeOptions_Declaration = exports.ExtensionRangeOptions_VerificationState = exports.ExtensionRangeOptions = exports.DescriptorProto_ReservedRange = exports.DescriptorProto_ExtensionRange = exports.DescriptorProto = exports.FileDescriptorProto = exports.FileDescriptorSet = exports.Edition = void 0;
16
+ exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annotation = exports.GeneratedCodeInfo = exports.SourceCodeInfo_Location = exports.SourceCodeInfo = exports.FeatureSetDefaults_FeatureSetEditionDefault = exports.FeatureSetDefaults = exports.FeatureSet_JsonFormat = exports.FeatureSet_MessageEncoding = exports.FeatureSet_Utf8Validation = exports.FeatureSet_RepeatedFieldEncoding = exports.FeatureSet_EnumType = exports.FeatureSet_FieldPresence = exports.FeatureSet = exports.UninterpretedOption_NamePart = exports.UninterpretedOption = exports.MethodOptions_IdempotencyLevel = exports.MethodOptions = exports.ServiceOptions = exports.EnumValueOptions = exports.EnumOptions = exports.OneofOptions = exports.FieldOptions_FeatureSupport = exports.FieldOptions_EditionDefault = exports.FieldOptions_OptionTargetType = exports.FieldOptions_OptionRetention = exports.FieldOptions_JSType = exports.FieldOptions_CType = exports.FieldOptions = exports.MessageOptions = exports.FileOptions_OptimizeMode = exports.FileOptions = exports.MethodDescriptorProto = exports.ServiceDescriptorProto = exports.EnumValueDescriptorProto = exports.EnumDescriptorProto_EnumReservedRange = exports.EnumDescriptorProto = exports.OneofDescriptorProto = exports.FieldDescriptorProto_Label = exports.FieldDescriptorProto_Type = exports.FieldDescriptorProto = exports.ExtensionRangeOptions_Declaration = exports.ExtensionRangeOptions_VerificationState = exports.ExtensionRangeOptions = exports.DescriptorProto_ReservedRange = exports.DescriptorProto_ExtensionRange = exports.DescriptorProto = exports.FileDescriptorProto = exports.FileDescriptorSet = exports.Edition = void 0;
17
17
  // Author: kenton@google.com (Kenton Varda)
18
18
  // Based on original Protocol Buffers design by
19
19
  // Sanjay Ghemawat, Jeff Dean, and others.
@@ -21,7 +21,7 @@ exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annota
21
21
  // The messages in this file describe the definitions found in .proto files.
22
22
  // A valid .proto file can be translated directly to a FileDescriptorProto
23
23
  // without any other information (e.g. without reading its imports).
24
- // @generated by protoc-gen-es v1.9.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
24
+ // @generated by protoc-gen-es v1.10.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
25
25
  // @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
26
26
  /* eslint-disable */
27
27
  const proto2_js_1 = require("../../proto2.js");
@@ -39,6 +39,13 @@ var Edition;
39
39
  * @generated from enum value: EDITION_UNKNOWN = 0;
40
40
  */
41
41
  Edition[Edition["EDITION_UNKNOWN"] = 0] = "EDITION_UNKNOWN";
42
+ /**
43
+ * A placeholder edition for specifying default behaviors *before* a feature
44
+ * was first introduced. This is effectively an "infinite past".
45
+ *
46
+ * @generated from enum value: EDITION_LEGACY = 900;
47
+ */
48
+ Edition[Edition["EDITION_LEGACY"] = 900] = "EDITION_LEGACY";
42
49
  /**
43
50
  * Legacy syntax "editions". These pre-date editions, but behave much like
44
51
  * distinct editions. These can't be used to specify the edition of proto
@@ -99,6 +106,7 @@ var Edition;
99
106
  // Retrieve enum metadata with: proto2.getEnumType(Edition)
100
107
  proto2_js_1.proto2.util.setEnumType(Edition, "google.protobuf.Edition", [
101
108
  { no: 0, name: "EDITION_UNKNOWN" },
109
+ { no: 900, name: "EDITION_LEGACY" },
102
110
  { no: 998, name: "EDITION_PROTO2" },
103
111
  { no: 999, name: "EDITION_PROTO3" },
104
112
  { no: 1000, name: "EDITION_2023" },
@@ -1040,6 +1048,7 @@ FieldOptions.fields = proto2_js_1.proto2.util.newFieldList(() => [
1040
1048
  { no: 19, name: "targets", kind: "enum", T: proto2_js_1.proto2.getEnumType(FieldOptions_OptionTargetType), repeated: true },
1041
1049
  { no: 20, name: "edition_defaults", kind: "message", T: FieldOptions_EditionDefault, repeated: true },
1042
1050
  { no: 21, name: "features", kind: "message", T: FeatureSet, opt: true },
1051
+ { no: 22, name: "feature_support", kind: "message", T: FieldOptions_FeatureSupport, opt: true },
1043
1052
  { no: 999, name: "uninterpreted_option", kind: "message", T: UninterpretedOption, repeated: true },
1044
1053
  ]);
1045
1054
  /**
@@ -1225,6 +1234,38 @@ FieldOptions_EditionDefault.fields = proto2_js_1.proto2.util.newFieldList(() =>
1225
1234
  { no: 3, name: "edition", kind: "enum", T: proto2_js_1.proto2.getEnumType(Edition), opt: true },
1226
1235
  { no: 2, name: "value", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1227
1236
  ]);
1237
+ /**
1238
+ * Information about the support window of a feature.
1239
+ *
1240
+ * @generated from message google.protobuf.FieldOptions.FeatureSupport
1241
+ */
1242
+ class FieldOptions_FeatureSupport extends message_js_1.Message {
1243
+ constructor(data) {
1244
+ super();
1245
+ proto2_js_1.proto2.util.initPartial(data, this);
1246
+ }
1247
+ static fromBinary(bytes, options) {
1248
+ return new FieldOptions_FeatureSupport().fromBinary(bytes, options);
1249
+ }
1250
+ static fromJson(jsonValue, options) {
1251
+ return new FieldOptions_FeatureSupport().fromJson(jsonValue, options);
1252
+ }
1253
+ static fromJsonString(jsonString, options) {
1254
+ return new FieldOptions_FeatureSupport().fromJsonString(jsonString, options);
1255
+ }
1256
+ static equals(a, b) {
1257
+ return proto2_js_1.proto2.util.equals(FieldOptions_FeatureSupport, a, b);
1258
+ }
1259
+ }
1260
+ exports.FieldOptions_FeatureSupport = FieldOptions_FeatureSupport;
1261
+ FieldOptions_FeatureSupport.runtime = proto2_js_1.proto2;
1262
+ FieldOptions_FeatureSupport.typeName = "google.protobuf.FieldOptions.FeatureSupport";
1263
+ FieldOptions_FeatureSupport.fields = proto2_js_1.proto2.util.newFieldList(() => [
1264
+ { no: 1, name: "edition_introduced", kind: "enum", T: proto2_js_1.proto2.getEnumType(Edition), opt: true },
1265
+ { no: 2, name: "edition_deprecated", kind: "enum", T: proto2_js_1.proto2.getEnumType(Edition), opt: true },
1266
+ { no: 3, name: "deprecation_warning", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1267
+ { no: 4, name: "edition_removed", kind: "enum", T: proto2_js_1.proto2.getEnumType(Edition), opt: true },
1268
+ ]);
1228
1269
  /**
1229
1270
  * @generated from message google.protobuf.OneofOptions
1230
1271
  */
@@ -1330,6 +1371,7 @@ EnumValueOptions.fields = proto2_js_1.proto2.util.newFieldList(() => [
1330
1371
  { no: 1, name: "deprecated", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true, default: false },
1331
1372
  { no: 2, name: "features", kind: "message", T: FeatureSet, opt: true },
1332
1373
  { no: 3, name: "debug_redact", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true, default: false },
1374
+ { no: 4, name: "feature_support", kind: "message", T: FieldOptions_FeatureSupport, opt: true },
1333
1375
  { no: 999, name: "uninterpreted_option", kind: "message", T: UninterpretedOption, repeated: true },
1334
1376
  ]);
1335
1377
  /**
@@ -1770,7 +1812,8 @@ FeatureSetDefaults_FeatureSetEditionDefault.runtime = proto2_js_1.proto2;
1770
1812
  FeatureSetDefaults_FeatureSetEditionDefault.typeName = "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault";
1771
1813
  FeatureSetDefaults_FeatureSetEditionDefault.fields = proto2_js_1.proto2.util.newFieldList(() => [
1772
1814
  { no: 3, name: "edition", kind: "enum", T: proto2_js_1.proto2.getEnumType(Edition), opt: true },
1773
- { no: 2, name: "features", kind: "message", T: FeatureSet, opt: true },
1815
+ { no: 4, name: "overridable_features", kind: "message", T: FeatureSet, opt: true },
1816
+ { no: 5, name: "fixed_features", kind: "message", T: FeatureSet, opt: true },
1774
1817
  ]);
1775
1818
  /**
1776
1819
  * Encapsulates information about the original source file from which a
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
17
- // @generated by protoc-gen-es v1.9.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.10.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
17
- // @generated by protoc-gen-es v1.9.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.10.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -25,7 +25,7 @@ export type { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptio
25
25
  export type { DescriptorSet, AnyDesc, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
26
26
  export { createDescriptorSet } from "./create-descriptor-set.js";
27
27
  export type { IMessageTypeRegistry, IExtensionRegistry, } from "./type-registry.js";
28
- export { createRegistry } from "./create-registry.js";
28
+ export { createRegistry, createMutableRegistry } from "./create-registry.js";
29
29
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
30
30
  export { toPlainMessage } from "./to-plain-message.js";
31
31
  export * from "./google/protobuf/compiler/plugin_pb.js";
package/dist/cjs/index.js CHANGED
@@ -27,7 +27,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
27
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.toPlainMessage = exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.clearExtension = exports.hasExtension = exports.setExtension = exports.getExtension = exports.ScalarType = exports.LongType = exports.isMessage = exports.Message = exports.codegenInfo = exports.protoDelimited = exports.protoBase64 = exports.protoInt64 = exports.protoDouble = exports.proto2 = exports.proto3 = void 0;
30
+ exports.toPlainMessage = exports.createRegistryFromDescriptors = exports.createMutableRegistry = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.clearExtension = exports.hasExtension = exports.setExtension = exports.getExtension = exports.ScalarType = exports.LongType = exports.isMessage = exports.Message = exports.codegenInfo = exports.protoDelimited = exports.protoBase64 = exports.protoInt64 = exports.protoDouble = exports.proto2 = exports.proto3 = void 0;
31
31
  var proto3_js_1 = require("./proto3.js");
32
32
  Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
33
33
  var proto2_js_1 = require("./proto2.js");
@@ -65,6 +65,7 @@ var create_descriptor_set_js_1 = require("./create-descriptor-set.js");
65
65
  Object.defineProperty(exports, "createDescriptorSet", { enumerable: true, get: function () { return create_descriptor_set_js_1.createDescriptorSet; } });
66
66
  var create_registry_js_1 = require("./create-registry.js");
67
67
  Object.defineProperty(exports, "createRegistry", { enumerable: true, get: function () { return create_registry_js_1.createRegistry; } });
68
+ Object.defineProperty(exports, "createMutableRegistry", { enumerable: true, get: function () { return create_registry_js_1.createMutableRegistry; } });
68
69
  var create_registry_from_desc_js_1 = require("./create-registry-from-desc.js");
69
70
  Object.defineProperty(exports, "createRegistryFromDescriptors", { enumerable: true, get: function () { return create_registry_from_desc_js_1.createRegistryFromDescriptors; } });
70
71
  var to_plain_message_js_1 = require("./to-plain-message.js");
@@ -75,12 +75,13 @@ function makeBinaryFormat() {
75
75
  let fieldNo, wireType;
76
76
  while (reader.pos < end) {
77
77
  [fieldNo, wireType] = reader.tag();
78
- if (wireType == binary_encoding_js_1.WireType.EndGroup) {
78
+ if (delimitedMessageEncoding === true &&
79
+ wireType == binary_encoding_js_1.WireType.EndGroup) {
79
80
  break;
80
81
  }
81
82
  const field = type.fields.find(fieldNo);
82
83
  if (!field) {
83
- const data = reader.skip(wireType);
84
+ const data = reader.skip(wireType, fieldNo);
84
85
  if (options.readUnknownFields) {
85
86
  this.onUnknownField(message, fieldNo, wireType, data);
86
87
  }
@@ -21,14 +21,14 @@ const proto_base64_js_1 = require("../proto-base64.js");
21
21
  */
22
22
  function getFeatureSetDefaults(options) {
23
23
  return descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec(
24
- /*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiADKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
24
+ /*upstream-inject-feature-defaults-start*/ "ChMY5gciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
25
25
  }
26
26
  /**
27
27
  * Create an edition feature resolver with the given feature set defaults, or
28
28
  * the feature set defaults supported by @bufbuild/protobuf.
29
29
  */
30
30
  function createFeatureResolver(edition, compiledFeatureSetDefaults, serializationOptions) {
31
- var _a, _b;
31
+ var _a;
32
32
  const fds = compiledFeatureSetDefaults !== null && compiledFeatureSetDefaults !== void 0 ? compiledFeatureSetDefaults : getFeatureSetDefaults(serializationOptions);
33
33
  const min = fds.minimumEdition;
34
34
  const max = fds.maximumEdition;
@@ -52,9 +52,23 @@ function createFeatureResolver(edition, compiledFeatureSetDefaults, serializatio
52
52
  if (highestMatch !== undefined && highestMatch.e > e) {
53
53
  continue;
54
54
  }
55
+ let f;
56
+ if (c.fixedFeatures && c.overridableFeatures) {
57
+ f = c.fixedFeatures;
58
+ f.fromBinary(c.overridableFeatures.toBinary());
59
+ }
60
+ else if (c.fixedFeatures) {
61
+ f = c.fixedFeatures;
62
+ }
63
+ else if (c.overridableFeatures) {
64
+ f = c.overridableFeatures;
65
+ }
66
+ else {
67
+ f = new descriptor_pb_js_1.FeatureSet();
68
+ }
55
69
  highestMatch = {
56
70
  e,
57
- f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
71
+ f,
58
72
  };
59
73
  }
60
74
  if (highestMatch === undefined) {
@@ -29,7 +29,7 @@ function makeUtilCommon() {
29
29
  const type = target.getType();
30
30
  for (const member of type.fields.byMember()) {
31
31
  const localName = member.localName, t = target, s = source;
32
- if (s[localName] === undefined) {
32
+ if (s[localName] == null) {
33
33
  // TODO if source is a Message instance, we should use isFieldSet() here to support future field presence
34
34
  continue;
35
35
  }
@@ -143,7 +143,17 @@ function makeUtilCommon() {
143
143
  }
144
144
  switch (m.kind) {
145
145
  case "message":
146
- return m.T.equals(va, vb);
146
+ let a = va;
147
+ let b = vb;
148
+ if (m.T.fieldWrapper) {
149
+ if (a !== undefined && !(0, is_message_js_1.isMessage)(a)) {
150
+ a = m.T.fieldWrapper.wrapField(a);
151
+ }
152
+ if (b !== undefined && !(0, is_message_js_1.isMessage)(b)) {
153
+ b = m.T.fieldWrapper.wrapField(b);
154
+ }
155
+ }
156
+ return m.T.equals(a, b);
147
157
  case "enum":
148
158
  return (0, scalars_js_1.scalarEquals)(scalar_js_1.ScalarType.INT32, va, vb);
149
159
  case "scalar":
@@ -55,3 +55,12 @@ export interface IExtensionRegistry {
55
55
  */
56
56
  findExtension(typeName: string): Extension | undefined;
57
57
  }
58
+ /**
59
+ * A registry that allows
60
+ */
61
+ export interface IMutableRegistry extends IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry, IExtensionRegistry {
62
+ /**
63
+ * Adds the type to the registry.
64
+ */
65
+ add(type: MessageType | EnumType | ServiceType | Extension): void;
66
+ }
@@ -61,7 +61,7 @@ export interface IBinaryReader {
61
61
  /**
62
62
  * Skip one element on the wire and return the skipped data.
63
63
  */
64
- skip(wireType: WireType): Uint8Array;
64
+ skip(wireType: WireType, fieldNo?: number): Uint8Array;
65
65
  /**
66
66
  * Read a `uint32` field, an unsigned 32 bit varint.
67
67
  */
@@ -347,10 +347,12 @@ export declare class BinaryReader implements IBinaryReader {
347
347
  */
348
348
  tag(): [number, WireType];
349
349
  /**
350
- * Skip one element on the wire and return the skipped data.
351
- * Supports WireType.StartGroup since v2.0.0-alpha.23.
350
+ * Skip one element and return the skipped data.
351
+ *
352
+ * When skipping StartGroup, provide the tags field number to check for
353
+ * matching field number in the EndGroup tag.
352
354
  */
353
- skip(wireType: WireType): Uint8Array;
355
+ skip(wireType: WireType, fieldNo?: number): Uint8Array;
354
356
  protected varint64: () => [number, number];
355
357
  /**
356
358
  * Throws error if position in byte array is out of range.
@@ -290,10 +290,12 @@ export class BinaryReader {
290
290
  return [fieldNo, wireType];
291
291
  }
292
292
  /**
293
- * Skip one element on the wire and return the skipped data.
294
- * Supports WireType.StartGroup since v2.0.0-alpha.23.
293
+ * Skip one element and return the skipped data.
294
+ *
295
+ * When skipping StartGroup, provide the tags field number to check for
296
+ * matching field number in the EndGroup tag.
295
297
  */
296
- skip(wireType) {
298
+ skip(wireType, fieldNo) {
297
299
  let start = this.pos;
298
300
  switch (wireType) {
299
301
  case WireType.Varint:
@@ -315,10 +317,15 @@ export class BinaryReader {
315
317
  this.pos += len;
316
318
  break;
317
319
  case WireType.StartGroup:
318
- // TODO check for matching field numbers in StartGroup / EndGroup tags
319
- let t;
320
- while ((t = this.tag()[1]) !== WireType.EndGroup) {
321
- this.skip(t);
320
+ for (;;) {
321
+ const [fn, wt] = this.tag();
322
+ if (wt === WireType.EndGroup) {
323
+ if (fieldNo !== undefined && fn !== fieldNo) {
324
+ throw new Error("invalid end group tag");
325
+ }
326
+ break;
327
+ }
328
+ this.skip(wt, fn);
322
329
  }
323
330
  break;
324
331
  default:
@@ -1,9 +1,13 @@
1
1
  import type { MessageType } from "./message-type.js";
2
2
  import type { EnumType } from "./enum.js";
3
3
  import type { ServiceType } from "./service-type.js";
4
- import type { IEnumTypeRegistry, IExtensionRegistry, IMessageTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
4
+ import type { IEnumTypeRegistry, IExtensionRegistry, IMessageTypeRegistry, IMutableRegistry, IServiceTypeRegistry } from "./type-registry.js";
5
5
  import type { Extension } from "./extension.js";
6
6
  /**
7
7
  * Create a new registry from the given types.
8
8
  */
9
9
  export declare function createRegistry(...types: Array<MessageType | EnumType | ServiceType | Extension>): IMessageTypeRegistry & IEnumTypeRegistry & IExtensionRegistry & IServiceTypeRegistry;
10
+ /**
11
+ * Create a mutable registry from the given types.
12
+ */
13
+ export declare function createMutableRegistry(...types: Array<MessageType | EnumType | ServiceType | Extension>): IMutableRegistry;
@@ -15,6 +15,14 @@
15
15
  * Create a new registry from the given types.
16
16
  */
17
17
  export function createRegistry(...types) {
18
+ const mutable = createMutableRegistry(...types);
19
+ delete mutable.add;
20
+ return mutable;
21
+ }
22
+ /**
23
+ * Create a mutable registry from the given types.
24
+ */
25
+ export function createMutableRegistry(...types) {
18
26
  const messages = {};
19
27
  const enums = {};
20
28
  const services = {};
@@ -38,53 +46,53 @@ export function createRegistry(...types) {
38
46
  var _a;
39
47
  return (_a = extensionsByName.get(typeName)) !== null && _a !== void 0 ? _a : undefined;
40
48
  },
41
- };
42
- function addType(type) {
43
- var _a;
44
- if ("fields" in type) {
45
- if (!registry.findMessage(type.typeName)) {
46
- messages[type.typeName] = type;
47
- type.fields.list().forEach(addField);
49
+ add(type) {
50
+ var _a;
51
+ if ("fields" in type) {
52
+ if (!this.findMessage(type.typeName)) {
53
+ messages[type.typeName] = type;
54
+ type.fields.list().forEach(addField);
55
+ }
48
56
  }
49
- }
50
- else if ("methods" in type) {
51
- if (!registry.findService(type.typeName)) {
52
- services[type.typeName] = type;
53
- for (const method of Object.values(type.methods)) {
54
- addType(method.I);
55
- addType(method.O);
57
+ else if ("methods" in type) {
58
+ if (!this.findService(type.typeName)) {
59
+ services[type.typeName] = type;
60
+ for (const method of Object.values(type.methods)) {
61
+ this.add(method.I);
62
+ this.add(method.O);
63
+ }
56
64
  }
57
65
  }
58
- }
59
- else if ("extendee" in type) {
60
- if (!extensionsByName.has(type.typeName)) {
61
- extensionsByName.set(type.typeName, type);
62
- const extendeeName = type.extendee.typeName;
63
- if (!extensionsByExtendee.has(extendeeName)) {
64
- extensionsByExtendee.set(extendeeName, new Map());
66
+ else if ("extendee" in type) {
67
+ if (!extensionsByName.has(type.typeName)) {
68
+ extensionsByName.set(type.typeName, type);
69
+ const extendeeName = type.extendee.typeName;
70
+ if (!extensionsByExtendee.has(extendeeName)) {
71
+ extensionsByExtendee.set(extendeeName, new Map());
72
+ }
73
+ (_a = extensionsByExtendee.get(extendeeName)) === null || _a === void 0 ? void 0 : _a.set(type.field.no, type);
74
+ this.add(type.extendee);
75
+ addField(type.field);
65
76
  }
66
- (_a = extensionsByExtendee.get(extendeeName)) === null || _a === void 0 ? void 0 : _a.set(type.field.no, type);
67
- addType(type.extendee);
68
- addField(type.field);
69
77
  }
70
- }
71
- else {
72
- enums[type.typeName] = type;
73
- }
74
- }
78
+ else {
79
+ enums[type.typeName] = type;
80
+ }
81
+ },
82
+ };
75
83
  function addField(field) {
76
84
  if (field.kind == "message") {
77
- addType(field.T);
85
+ registry.add(field.T);
78
86
  }
79
87
  else if (field.kind == "map" && field.V.kind == "message") {
80
- addType(field.V.T);
88
+ registry.add(field.V.T);
81
89
  }
82
90
  else if (field.kind == "enum") {
83
- addType(field.T);
91
+ registry.add(field.T);
84
92
  }
85
93
  }
86
94
  for (const type of types) {
87
- addType(type);
95
+ registry.add(type);
88
96
  }
89
97
  return registry;
90
98
  }
@@ -70,7 +70,7 @@ export function setExtension(message, extension, value, options) {
70
70
  const reader = readOpt.readerFactory(writer.finish());
71
71
  while (reader.pos < reader.len) {
72
72
  const [no, wireType] = reader.tag();
73
- const data = reader.skip(wireType);
73
+ const data = reader.skip(wireType, no);
74
74
  message.getType().runtime.bin.onUnknownField(message, no, wireType, data);
75
75
  }
76
76
  }
@@ -16,6 +16,13 @@ export declare enum Edition {
16
16
  * @generated from enum value: EDITION_UNKNOWN = 0;
17
17
  */
18
18
  EDITION_UNKNOWN = 0,
19
+ /**
20
+ * A placeholder edition for specifying default behaviors *before* a feature
21
+ * was first introduced. This is effectively an "infinite past".
22
+ *
23
+ * @generated from enum value: EDITION_LEGACY = 900;
24
+ */
25
+ EDITION_LEGACY = 900,
19
26
  /**
20
27
  * Legacy syntax "editions". These pre-date editions, but behave much like
21
28
  * distinct editions. These can't be used to specify the edition of proto
@@ -876,12 +883,16 @@ export declare class FileOptions extends Message<FileOptions> {
876
883
  */
877
884
  javaGenerateEqualsAndHash?: boolean;
878
885
  /**
879
- * If set true, then the Java2 code generator will generate code that
880
- * throws an exception whenever an attempt is made to assign a non-UTF-8
881
- * byte sequence to a string field.
882
- * Message reflection will do the same.
883
- * However, an extension field still accepts non-UTF-8 byte sequences.
884
- * This option has no effect on when used with the lite runtime.
886
+ * A proto2 file can set this to true to opt in to UTF-8 checking for Java,
887
+ * which will throw an exception if invalid UTF-8 is parsed from the wire or
888
+ * assigned to a string field.
889
+ *
890
+ * TODO: clarify exactly what kinds of field types this option
891
+ * applies to, and update these docs accordingly.
892
+ *
893
+ * Proto3 files already perform these checks. Setting the option explicitly to
894
+ * false has no effect: it cannot be used to opt proto3 files out of UTF-8
895
+ * checks.
885
896
  *
886
897
  * @generated from field: optional bool java_string_check_utf8 = 27 [default = false];
887
898
  */
@@ -1266,6 +1277,10 @@ export declare class FieldOptions extends Message<FieldOptions> {
1266
1277
  * @generated from field: optional google.protobuf.FeatureSet features = 21;
1267
1278
  */
1268
1279
  features?: FeatureSet;
1280
+ /**
1281
+ * @generated from field: optional google.protobuf.FieldOptions.FeatureSupport feature_support = 22;
1282
+ */
1283
+ featureSupport?: FieldOptions_FeatureSupport;
1269
1284
  /**
1270
1285
  * The parser stores options it doesn't recognize here. See above.
1271
1286
  *
@@ -1424,6 +1439,51 @@ export declare class FieldOptions_EditionDefault extends Message<FieldOptions_Ed
1424
1439
  static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): FieldOptions_EditionDefault;
1425
1440
  static equals(a: FieldOptions_EditionDefault | PlainMessage<FieldOptions_EditionDefault> | undefined, b: FieldOptions_EditionDefault | PlainMessage<FieldOptions_EditionDefault> | undefined): boolean;
1426
1441
  }
1442
+ /**
1443
+ * Information about the support window of a feature.
1444
+ *
1445
+ * @generated from message google.protobuf.FieldOptions.FeatureSupport
1446
+ */
1447
+ export declare class FieldOptions_FeatureSupport extends Message<FieldOptions_FeatureSupport> {
1448
+ /**
1449
+ * The edition that this feature was first available in. In editions
1450
+ * earlier than this one, the default assigned to EDITION_LEGACY will be
1451
+ * used, and proto files will not be able to override it.
1452
+ *
1453
+ * @generated from field: optional google.protobuf.Edition edition_introduced = 1;
1454
+ */
1455
+ editionIntroduced?: Edition;
1456
+ /**
1457
+ * The edition this feature becomes deprecated in. Using this after this
1458
+ * edition may trigger warnings.
1459
+ *
1460
+ * @generated from field: optional google.protobuf.Edition edition_deprecated = 2;
1461
+ */
1462
+ editionDeprecated?: Edition;
1463
+ /**
1464
+ * The deprecation warning text if this feature is used after the edition it
1465
+ * was marked deprecated in.
1466
+ *
1467
+ * @generated from field: optional string deprecation_warning = 3;
1468
+ */
1469
+ deprecationWarning?: string;
1470
+ /**
1471
+ * The edition this feature is no longer available in. In editions after
1472
+ * this one, the last default assigned will be used, and proto files will
1473
+ * not be able to override it.
1474
+ *
1475
+ * @generated from field: optional google.protobuf.Edition edition_removed = 4;
1476
+ */
1477
+ editionRemoved?: Edition;
1478
+ constructor(data?: PartialMessage<FieldOptions_FeatureSupport>);
1479
+ static readonly runtime: typeof proto2;
1480
+ static readonly typeName = "google.protobuf.FieldOptions.FeatureSupport";
1481
+ static readonly fields: FieldList;
1482
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FieldOptions_FeatureSupport;
1483
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): FieldOptions_FeatureSupport;
1484
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): FieldOptions_FeatureSupport;
1485
+ static equals(a: FieldOptions_FeatureSupport | PlainMessage<FieldOptions_FeatureSupport> | undefined, b: FieldOptions_FeatureSupport | PlainMessage<FieldOptions_FeatureSupport> | undefined): boolean;
1486
+ }
1427
1487
  /**
1428
1488
  * @generated from message google.protobuf.OneofOptions
1429
1489
  */
@@ -1529,6 +1589,12 @@ export declare class EnumValueOptions extends Message<EnumValueOptions> {
1529
1589
  * @generated from field: optional bool debug_redact = 3 [default = false];
1530
1590
  */
1531
1591
  debugRedact?: boolean;
1592
+ /**
1593
+ * Information about the support window of a feature value.
1594
+ *
1595
+ * @generated from field: optional google.protobuf.FieldOptions.FeatureSupport feature_support = 4;
1596
+ */
1597
+ featureSupport?: FieldOptions_FeatureSupport;
1532
1598
  /**
1533
1599
  * The parser stores options it doesn't recognize here. See above.
1534
1600
  *
@@ -1919,9 +1985,17 @@ export declare class FeatureSetDefaults_FeatureSetEditionDefault extends Message
1919
1985
  */
1920
1986
  edition?: Edition;
1921
1987
  /**
1922
- * @generated from field: optional google.protobuf.FeatureSet features = 2;
1988
+ * Defaults of features that can be overridden in this edition.
1989
+ *
1990
+ * @generated from field: optional google.protobuf.FeatureSet overridable_features = 4;
1923
1991
  */
1924
- features?: FeatureSet;
1992
+ overridableFeatures?: FeatureSet;
1993
+ /**
1994
+ * Defaults of features that can't be overridden in this edition.
1995
+ *
1996
+ * @generated from field: optional google.protobuf.FeatureSet fixed_features = 5;
1997
+ */
1998
+ fixedFeatures?: FeatureSet;
1925
1999
  constructor(data?: PartialMessage<FeatureSetDefaults_FeatureSetEditionDefault>);
1926
2000
  static readonly runtime: typeof proto2;
1927
2001
  static readonly typeName = "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault";
@@ -18,7 +18,7 @@
18
18
  // The messages in this file describe the definitions found in .proto files.
19
19
  // A valid .proto file can be translated directly to a FileDescriptorProto
20
20
  // without any other information (e.g. without reading its imports).
21
- // @generated by protoc-gen-es v1.9.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
21
+ // @generated by protoc-gen-es v1.10.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
22
22
  // @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
23
23
  /* eslint-disable */
24
24
  import { proto2 } from "../../proto2.js";
@@ -36,6 +36,13 @@ export var Edition;
36
36
  * @generated from enum value: EDITION_UNKNOWN = 0;
37
37
  */
38
38
  Edition[Edition["EDITION_UNKNOWN"] = 0] = "EDITION_UNKNOWN";
39
+ /**
40
+ * A placeholder edition for specifying default behaviors *before* a feature
41
+ * was first introduced. This is effectively an "infinite past".
42
+ *
43
+ * @generated from enum value: EDITION_LEGACY = 900;
44
+ */
45
+ Edition[Edition["EDITION_LEGACY"] = 900] = "EDITION_LEGACY";
39
46
  /**
40
47
  * Legacy syntax "editions". These pre-date editions, but behave much like
41
48
  * distinct editions. These can't be used to specify the edition of proto
@@ -96,6 +103,7 @@ export var Edition;
96
103
  // Retrieve enum metadata with: proto2.getEnumType(Edition)
97
104
  proto2.util.setEnumType(Edition, "google.protobuf.Edition", [
98
105
  { no: 0, name: "EDITION_UNKNOWN" },
106
+ { no: 900, name: "EDITION_LEGACY" },
99
107
  { no: 998, name: "EDITION_PROTO2" },
100
108
  { no: 999, name: "EDITION_PROTO3" },
101
109
  { no: 1000, name: "EDITION_2023" },
@@ -1020,6 +1028,7 @@ FieldOptions.fields = proto2.util.newFieldList(() => [
1020
1028
  { no: 19, name: "targets", kind: "enum", T: proto2.getEnumType(FieldOptions_OptionTargetType), repeated: true },
1021
1029
  { no: 20, name: "edition_defaults", kind: "message", T: FieldOptions_EditionDefault, repeated: true },
1022
1030
  { no: 21, name: "features", kind: "message", T: FeatureSet, opt: true },
1031
+ { no: 22, name: "feature_support", kind: "message", T: FieldOptions_FeatureSupport, opt: true },
1023
1032
  { no: 999, name: "uninterpreted_option", kind: "message", T: UninterpretedOption, repeated: true },
1024
1033
  ]);
1025
1034
  /**
@@ -1204,6 +1213,37 @@ FieldOptions_EditionDefault.fields = proto2.util.newFieldList(() => [
1204
1213
  { no: 3, name: "edition", kind: "enum", T: proto2.getEnumType(Edition), opt: true },
1205
1214
  { no: 2, name: "value", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1206
1215
  ]);
1216
+ /**
1217
+ * Information about the support window of a feature.
1218
+ *
1219
+ * @generated from message google.protobuf.FieldOptions.FeatureSupport
1220
+ */
1221
+ export class FieldOptions_FeatureSupport extends Message {
1222
+ constructor(data) {
1223
+ super();
1224
+ proto2.util.initPartial(data, this);
1225
+ }
1226
+ static fromBinary(bytes, options) {
1227
+ return new FieldOptions_FeatureSupport().fromBinary(bytes, options);
1228
+ }
1229
+ static fromJson(jsonValue, options) {
1230
+ return new FieldOptions_FeatureSupport().fromJson(jsonValue, options);
1231
+ }
1232
+ static fromJsonString(jsonString, options) {
1233
+ return new FieldOptions_FeatureSupport().fromJsonString(jsonString, options);
1234
+ }
1235
+ static equals(a, b) {
1236
+ return proto2.util.equals(FieldOptions_FeatureSupport, a, b);
1237
+ }
1238
+ }
1239
+ FieldOptions_FeatureSupport.runtime = proto2;
1240
+ FieldOptions_FeatureSupport.typeName = "google.protobuf.FieldOptions.FeatureSupport";
1241
+ FieldOptions_FeatureSupport.fields = proto2.util.newFieldList(() => [
1242
+ { no: 1, name: "edition_introduced", kind: "enum", T: proto2.getEnumType(Edition), opt: true },
1243
+ { no: 2, name: "edition_deprecated", kind: "enum", T: proto2.getEnumType(Edition), opt: true },
1244
+ { no: 3, name: "deprecation_warning", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1245
+ { no: 4, name: "edition_removed", kind: "enum", T: proto2.getEnumType(Edition), opt: true },
1246
+ ]);
1207
1247
  /**
1208
1248
  * @generated from message google.protobuf.OneofOptions
1209
1249
  */
@@ -1306,6 +1346,7 @@ EnumValueOptions.fields = proto2.util.newFieldList(() => [
1306
1346
  { no: 1, name: "deprecated", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true, default: false },
1307
1347
  { no: 2, name: "features", kind: "message", T: FeatureSet, opt: true },
1308
1348
  { no: 3, name: "debug_redact", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true, default: false },
1349
+ { no: 4, name: "feature_support", kind: "message", T: FieldOptions_FeatureSupport, opt: true },
1309
1350
  { no: 999, name: "uninterpreted_option", kind: "message", T: UninterpretedOption, repeated: true },
1310
1351
  ]);
1311
1352
  /**
@@ -1739,7 +1780,8 @@ FeatureSetDefaults_FeatureSetEditionDefault.runtime = proto2;
1739
1780
  FeatureSetDefaults_FeatureSetEditionDefault.typeName = "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault";
1740
1781
  FeatureSetDefaults_FeatureSetEditionDefault.fields = proto2.util.newFieldList(() => [
1741
1782
  { no: 3, name: "edition", kind: "enum", T: proto2.getEnumType(Edition), opt: true },
1742
- { no: 2, name: "features", kind: "message", T: FeatureSet, opt: true },
1783
+ { no: 4, name: "overridable_features", kind: "message", T: FeatureSet, opt: true },
1784
+ { no: 5, name: "fixed_features", kind: "message", T: FeatureSet, opt: true },
1743
1785
  ]);
1744
1786
  /**
1745
1787
  * Encapsulates information about the original source file from which a
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v1.9.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.10.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v1.9.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.10.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -25,7 +25,7 @@ export type { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptio
25
25
  export type { DescriptorSet, AnyDesc, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
26
26
  export { createDescriptorSet } from "./create-descriptor-set.js";
27
27
  export type { IMessageTypeRegistry, IExtensionRegistry, } from "./type-registry.js";
28
- export { createRegistry } from "./create-registry.js";
28
+ export { createRegistry, createMutableRegistry } from "./create-registry.js";
29
29
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
30
30
  export { toPlainMessage } from "./to-plain-message.js";
31
31
  export * from "./google/protobuf/compiler/plugin_pb.js";
package/dist/esm/index.js CHANGED
@@ -25,7 +25,7 @@ export { getExtension, setExtension, hasExtension, clearExtension, } from "./ext
25
25
  export { MethodKind, MethodIdempotency } from "./service-type.js";
26
26
  export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
27
27
  export { createDescriptorSet } from "./create-descriptor-set.js";
28
- export { createRegistry } from "./create-registry.js";
28
+ export { createRegistry, createMutableRegistry } from "./create-registry.js";
29
29
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
30
30
  export { toPlainMessage } from "./to-plain-message.js";
31
31
  // ideally, we would export these types with sub-path exports:
@@ -73,12 +73,13 @@ export function makeBinaryFormat() {
73
73
  let fieldNo, wireType;
74
74
  while (reader.pos < end) {
75
75
  [fieldNo, wireType] = reader.tag();
76
- if (wireType == WireType.EndGroup) {
76
+ if (delimitedMessageEncoding === true &&
77
+ wireType == WireType.EndGroup) {
77
78
  break;
78
79
  }
79
80
  const field = type.fields.find(fieldNo);
80
81
  if (!field) {
81
- const data = reader.skip(wireType);
82
+ const data = reader.skip(wireType, fieldNo);
82
83
  if (options.readUnknownFields) {
83
84
  this.onUnknownField(message, fieldNo, wireType, data);
84
85
  }
@@ -18,14 +18,14 @@ import { protoBase64 } from "../proto-base64.js";
18
18
  */
19
19
  function getFeatureSetDefaults(options) {
20
20
  return FeatureSetDefaults.fromBinary(protoBase64.dec(
21
- /*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiADKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
21
+ /*upstream-inject-feature-defaults-start*/ "ChMY5gciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
22
22
  }
23
23
  /**
24
24
  * Create an edition feature resolver with the given feature set defaults, or
25
25
  * the feature set defaults supported by @bufbuild/protobuf.
26
26
  */
27
27
  export function createFeatureResolver(edition, compiledFeatureSetDefaults, serializationOptions) {
28
- var _a, _b;
28
+ var _a;
29
29
  const fds = compiledFeatureSetDefaults !== null && compiledFeatureSetDefaults !== void 0 ? compiledFeatureSetDefaults : getFeatureSetDefaults(serializationOptions);
30
30
  const min = fds.minimumEdition;
31
31
  const max = fds.maximumEdition;
@@ -49,9 +49,23 @@ export function createFeatureResolver(edition, compiledFeatureSetDefaults, seria
49
49
  if (highestMatch !== undefined && highestMatch.e > e) {
50
50
  continue;
51
51
  }
52
+ let f;
53
+ if (c.fixedFeatures && c.overridableFeatures) {
54
+ f = c.fixedFeatures;
55
+ f.fromBinary(c.overridableFeatures.toBinary());
56
+ }
57
+ else if (c.fixedFeatures) {
58
+ f = c.fixedFeatures;
59
+ }
60
+ else if (c.overridableFeatures) {
61
+ f = c.overridableFeatures;
62
+ }
63
+ else {
64
+ f = new FeatureSet();
65
+ }
52
66
  highestMatch = {
53
67
  e,
54
- f: (_b = c.features) !== null && _b !== void 0 ? _b : new FeatureSet(),
68
+ f,
55
69
  };
56
70
  }
57
71
  if (highestMatch === undefined) {
@@ -27,7 +27,7 @@ export function makeUtilCommon() {
27
27
  const type = target.getType();
28
28
  for (const member of type.fields.byMember()) {
29
29
  const localName = member.localName, t = target, s = source;
30
- if (s[localName] === undefined) {
30
+ if (s[localName] == null) {
31
31
  // TODO if source is a Message instance, we should use isFieldSet() here to support future field presence
32
32
  continue;
33
33
  }
@@ -141,7 +141,17 @@ export function makeUtilCommon() {
141
141
  }
142
142
  switch (m.kind) {
143
143
  case "message":
144
- return m.T.equals(va, vb);
144
+ let a = va;
145
+ let b = vb;
146
+ if (m.T.fieldWrapper) {
147
+ if (a !== undefined && !isMessage(a)) {
148
+ a = m.T.fieldWrapper.wrapField(a);
149
+ }
150
+ if (b !== undefined && !isMessage(b)) {
151
+ b = m.T.fieldWrapper.wrapField(b);
152
+ }
153
+ }
154
+ return m.T.equals(a, b);
145
155
  case "enum":
146
156
  return scalarEquals(ScalarType.INT32, va, vb);
147
157
  case "scalar":
@@ -55,3 +55,12 @@ export interface IExtensionRegistry {
55
55
  */
56
56
  findExtension(typeName: string): Extension | undefined;
57
57
  }
58
+ /**
59
+ * A registry that allows
60
+ */
61
+ export interface IMutableRegistry extends IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry, IExtensionRegistry {
62
+ /**
63
+ * Adds the type to the registry.
64
+ */
65
+ add(type: MessageType | EnumType | ServiceType | Extension): void;
66
+ }
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
+ "keywords": [
7
+ "protobuf",
8
+ "schema",
9
+ "typescript",
10
+ "ecmascript"
11
+ ],
6
12
  "repository": {
7
13
  "type": "git",
8
14
  "url": "https://github.com/bufbuild/protobuf-es.git",
@@ -30,8 +36,5 @@
30
36
  },
31
37
  "devDependencies": {
32
38
  "upstream-protobuf": "*"
33
- },
34
- "files": [
35
- "dist/**"
36
- ]
39
+ }
37
40
  }