protobufjs 8.0.0-experimental → 8.0.3-experimental

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.0.0-experimental (c) 2016, daniel wirtz
3
- * compiled fri, 21 mar 2025 17:14:14 utc
2
+ * protobuf.js v8.0.3-experimental (c) 2016, daniel wirtz
3
+ * compiled tue, 25 mar 2025 02:15:04 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.0.0-experimental (c) 2016, daniel wirtz
3
- * compiled fri, 21 mar 2025 17:14:14 utc
2
+ * protobuf.js v8.0.3-experimental (c) 2016, daniel wirtz
3
+ * compiled tue, 25 mar 2025 02:15:04 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
package/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.0.0-experimental (c) 2016, daniel wirtz
3
- * compiled fri, 21 mar 2025 17:14:14 utc
2
+ * protobuf.js v8.0.3-experimental (c) 2016, daniel wirtz
3
+ * compiled tue, 25 mar 2025 02:15:04 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -2821,7 +2821,7 @@ protobuf.types = require(36);
2821
2821
  protobuf.util = require(37);
2822
2822
 
2823
2823
  // Set up possibly cyclic reflection dependencies
2824
- protobuf.ReflectionObject._configure(protobuf.Root);
2824
+ protobuf.ReflectionObject._configure(protobuf.Root, protobuf.Namespace);
2825
2825
  protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
2826
2826
  protobuf.Root._configure(protobuf.Type);
2827
2827
  protobuf.Field._configure(protobuf.Type);
@@ -3753,7 +3753,7 @@ ReflectionObject.className = "ReflectionObject";
3753
3753
  const OneOf = require(25);
3754
3754
  var util = require(37);
3755
3755
 
3756
- var Root; // cyclic
3756
+ var Root, Namespace; // cyclic
3757
3757
 
3758
3758
  /* eslint-disable no-warning-comments */
3759
3759
  // TODO: Replace with embedded proto.
@@ -3910,7 +3910,8 @@ ReflectionObject.prototype.onRemove = function onRemove(parent) {
3910
3910
  ReflectionObject.prototype.resolve = function resolve() {
3911
3911
  if (this.resolved)
3912
3912
  return this;
3913
- if (this instanceof Root || this.parent && this.parent.resolved) {
3913
+ var edition = this.getOption("edition");
3914
+ if ((this instanceof Namespace && edition) || (this.parent && this.parent.resolved)) {
3914
3915
  this._resolveFeatures();
3915
3916
  this.resolved = true;
3916
3917
  }
@@ -3924,24 +3925,27 @@ ReflectionObject.prototype.resolve = function resolve() {
3924
3925
  ReflectionObject.prototype._resolveFeatures = function _resolveFeatures() {
3925
3926
  var defaults = {};
3926
3927
 
3927
- var edition = this.root.getOption("edition");
3928
- if (this instanceof Root) {
3929
- if (this.root.getOption("syntax") === "proto3") {
3928
+ var protoFeatures = Object.assign(Object.assign({}, this._protoFeatures), this._inferLegacyProtoFeatures(edition));
3929
+
3930
+ var edition = this.getOption("edition");
3931
+ if (this instanceof Namespace && edition) {
3932
+ // For a namespace marked with a specific edition, reset defaults.
3933
+ if (edition === "proto2") {
3934
+ defaults = Object.assign({}, proto2Defaults);
3935
+ } else if (edition === "proto3") {
3930
3936
  defaults = Object.assign({}, proto3Defaults);
3931
3937
  } else if (edition === "2023") {
3932
3938
  defaults = Object.assign({}, editions2023Defaults);
3933
3939
  } else {
3934
- defaults = Object.assign({}, proto2Defaults);
3940
+ throw new Error("Unknown edition: " + edition);
3935
3941
  }
3942
+ this._features = Object.assign(defaults, protoFeatures || {});
3943
+ return;
3936
3944
  }
3937
3945
 
3938
- var protoFeatures = Object.assign(Object.assign({}, this._protoFeatures), this._inferLegacyProtoFeatures(edition));
3939
-
3940
- if (this instanceof Root) {
3941
- this._features = Object.assign(defaults, protoFeatures || {});
3942
3946
  // fields in Oneofs aren't actually children of them, so we have to
3943
3947
  // special-case it
3944
- } else if (this.partOf instanceof OneOf) {
3948
+ if (this.partOf instanceof OneOf) {
3945
3949
  var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
3946
3950
  this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
3947
3951
  } else if (this.declaringField) {
@@ -3988,8 +3992,10 @@ ReflectionObject.prototype.getOption = function getOption(name) {
3988
3992
  * @returns {ReflectionObject} `this`
3989
3993
  */
3990
3994
  ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
3991
- if (!ifNotSet || !this.options || this.options[name] === undefined)
3995
+ if (!ifNotSet || !this.options || this.options[name] === undefined) {
3996
+ if (this.getOption(name) !== value) this.resolved = false;
3992
3997
  (this.options || (this.options = {}))[name] = value;
3998
+ }
3993
3999
  return this;
3994
4000
  };
3995
4001
 
@@ -4065,8 +4071,9 @@ ReflectionObject.prototype.toString = function toString() {
4065
4071
  };
4066
4072
 
4067
4073
  // Sets up cyclic dependencies (called in index-light)
4068
- ReflectionObject._configure = function(Root_) {
4074
+ ReflectionObject._configure = function(Root_, Namespace_) {
4069
4075
  Root = Root_;
4076
+ Namespace = Namespace_;
4070
4077
  };
4071
4078
 
4072
4079
  },{"25":25,"37":37}],25:[function(require,module,exports){
@@ -4329,7 +4336,6 @@ var base10Re = /^[1-9][0-9]*$/,
4329
4336
  * @property {string|undefined} package Package name, if declared
4330
4337
  * @property {string[]|undefined} imports Imports, if any
4331
4338
  * @property {string[]|undefined} weakImports Weak imports, if any
4332
- * @property {string|undefined} syntax Syntax, if specified (either `"proto2"` or `"proto3"`)
4333
4339
  * @property {Root} root Populated root instance
4334
4340
  */
4335
4341
 
@@ -4377,9 +4383,9 @@ function parse(source, root, options) {
4377
4383
  pkg,
4378
4384
  imports,
4379
4385
  weakImports,
4380
- syntax,
4381
- edition = false,
4382
- isProto3 = false;
4386
+ edition = "proto2",
4387
+ isProto3 = false,
4388
+ isProto2 = true;
4383
4389
 
4384
4390
  var ptr = root;
4385
4391
 
@@ -4441,7 +4447,7 @@ function parse(source, root, options) {
4441
4447
  try {
4442
4448
  target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]);
4443
4449
  } catch (err) {
4444
- if (typeRefRe.test(token) && edition) {
4450
+ if (typeRefRe.test(token) && (!isProto2 && !isProto3)) {
4445
4451
  target.push(token);
4446
4452
  } else {
4447
4453
  throw err;
@@ -4524,7 +4530,6 @@ function parse(source, root, options) {
4524
4530
  }
4525
4531
 
4526
4532
  function parsePackage() {
4527
-
4528
4533
  /* istanbul ignore if */
4529
4534
  if (pkg !== undefined)
4530
4535
  throw illegal("package");
@@ -4536,6 +4541,12 @@ function parse(source, root, options) {
4536
4541
  throw illegal(pkg, "name");
4537
4542
 
4538
4543
  ptr = ptr.define(pkg);
4544
+
4545
+ var oldEdition = ptr.getOption("edition");
4546
+ if (oldEdition && oldEdition !== edition) {
4547
+ throw new Error("incompatible editions detected in package " + pkg + ": " + edition + " vs " + oldEdition);
4548
+ }
4549
+ ptr.setOption("edition", edition);
4539
4550
  skip(";");
4540
4551
  }
4541
4552
 
@@ -4561,16 +4572,17 @@ function parse(source, root, options) {
4561
4572
 
4562
4573
  function parseSyntax() {
4563
4574
  skip("=");
4564
- syntax = readString();
4565
- isProto3 = syntax === "proto3";
4575
+ edition = readString();
4576
+ isProto3 = edition === "proto3";
4577
+ isProto2 = edition === "proto2";
4566
4578
 
4567
4579
  /* istanbul ignore if */
4568
- if (!isProto3 && syntax !== "proto2")
4569
- throw illegal(syntax, "syntax");
4580
+ if (!isProto3 && !isProto2)
4581
+ throw illegal(edition, "syntax");
4570
4582
 
4571
4583
  // Syntax is needed to understand the meaning of the optional field rule
4572
4584
  // Otherwise the meaning is ambiguous between proto2 and proto3
4573
- root.setOption("syntax", syntax);
4585
+ root.setOption("edition", edition);
4574
4586
 
4575
4587
  skip(";");
4576
4588
  }
@@ -4578,6 +4590,8 @@ function parse(source, root, options) {
4578
4590
  function parseEdition() {
4579
4591
  skip("=");
4580
4592
  edition = readString();
4593
+ isProto3 = false;
4594
+ isProto2 = false;
4581
4595
  const supportedEditions = ["2023"];
4582
4596
 
4583
4597
  /* istanbul ignore if */
@@ -4657,7 +4671,7 @@ function parse(source, root, options) {
4657
4671
  break;
4658
4672
 
4659
4673
  case "required":
4660
- if (edition)
4674
+ if (!isProto2)
4661
4675
  throw illegal(token);
4662
4676
  /* eslint-disable no-fallthrough */
4663
4677
  case "repeated":
@@ -4668,7 +4682,7 @@ function parse(source, root, options) {
4668
4682
  /* istanbul ignore if */
4669
4683
  if (isProto3) {
4670
4684
  parseField(type, "proto3_optional");
4671
- } else if (edition) {
4685
+ } else if (!isProto2) {
4672
4686
  throw illegal(token);
4673
4687
  } else {
4674
4688
  parseField(type, "optional");
@@ -4689,7 +4703,7 @@ function parse(source, root, options) {
4689
4703
 
4690
4704
  default:
4691
4705
  /* istanbul ignore if */
4692
- if (!isProto3 && !edition || !typeRefRe.test(token)) {
4706
+ if (isProto2 || !typeRefRe.test(token)) {
4693
4707
  throw illegal(token);
4694
4708
  }
4695
4709
 
@@ -5150,7 +5164,7 @@ function parse(source, root, options) {
5150
5164
 
5151
5165
  default:
5152
5166
  /* istanbul ignore if */
5153
- if (!isProto3 && !edition || !typeRefRe.test(token))
5167
+ if (isProto2 || !typeRefRe.test(token))
5154
5168
  throw illegal(token);
5155
5169
  push(token);
5156
5170
  parseField(parent, "optional", reference);
@@ -5220,7 +5234,6 @@ function parse(source, root, options) {
5220
5234
  "package" : pkg,
5221
5235
  "imports" : imports,
5222
5236
  weakImports : weakImports,
5223
- syntax : syntax,
5224
5237
  root : root
5225
5238
  };
5226
5239
  }
@@ -5746,6 +5759,9 @@ function Root(options) {
5746
5759
  * @type {string[]}
5747
5760
  */
5748
5761
  this.files = [];
5762
+
5763
+ // Default to proto2 if not specified.
5764
+ this.setOption("edition", "proto2", true);
5749
5765
  }
5750
5766
 
5751
5767
  /**