protobufjs 8.0.4-experimental → 8.1.1-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.4-experimental (c) 2016, daniel wirtz
3
- * compiled thu, 27 mar 2025 04:14:10 utc
2
+ * protobuf.js v8.1.1-experimental (c) 2016, daniel wirtz
3
+ * compiled wed, 07 may 2025 22:28:18 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -1707,12 +1707,6 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1707
1707
  */
1708
1708
  this._valuesFeatures = {};
1709
1709
 
1710
- /**
1711
- * Unresolved values features, if any
1712
- * @type {Object<string, Object<string, *>>|undefined}
1713
- */
1714
- this._valuesProtoFeatures = {};
1715
-
1716
1710
  /**
1717
1711
  * Reserved ranges, if any.
1718
1712
  * @type {Array.<number[]|string>}
@@ -1733,12 +1727,12 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1733
1727
  * @override
1734
1728
  */
1735
1729
  Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
1736
- var edition = this._edition || edition;
1730
+ edition = this._edition || edition;
1737
1731
  ReflectionObject.prototype._resolveFeatures.call(this, edition);
1738
1732
 
1739
- Object.keys(this._valuesProtoFeatures).forEach(key => {
1733
+ Object.keys(this.values).forEach(key => {
1740
1734
  var parentFeaturesCopy = Object.assign({}, this._features);
1741
- this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this._valuesProtoFeatures[key] || {});
1735
+ this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this.valuesOptions && this.valuesOptions[key] && this.valuesOptions[key].features);
1742
1736
  });
1743
1737
 
1744
1738
  return this;
@@ -1824,21 +1818,6 @@ Enum.prototype.add = function add(name, id, comment, options) {
1824
1818
  if (this.valuesOptions === undefined)
1825
1819
  this.valuesOptions = {};
1826
1820
  this.valuesOptions[name] = options || null;
1827
-
1828
- for (var key of Object.keys(this.valuesOptions)) {
1829
- var features = Array.isArray(this.valuesOptions[key]) ? this.valuesOptions[key].find(x => {return Object.prototype.hasOwnProperty.call(x, "features");}) : this.valuesOptions[key] === "features";
1830
- if (features) {
1831
- this._valuesProtoFeatures[key] = features.features;
1832
- } else {
1833
- this._valuesProtoFeatures[key] = {};
1834
- }
1835
- }
1836
- }
1837
-
1838
- for (var enumValue of Object.keys(this.values)) {
1839
- if (!this._valuesProtoFeatures[enumValue]) {
1840
- this._valuesProtoFeatures[enumValue] = {};
1841
- }
1842
1821
  }
1843
1822
 
1844
1823
  this.comments[name] = comment || null;
@@ -2257,16 +2236,22 @@ Field.prototype.resolve = function resolve() {
2257
2236
  */
2258
2237
  Field.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(edition) {
2259
2238
  if (edition !== "proto2" && edition !== "proto3") {
2260
- return;
2239
+ return {};
2261
2240
  }
2262
2241
 
2263
2242
  var features = {};
2264
- this.resolve();
2243
+
2265
2244
  if (this.rule === "required") {
2266
2245
  features.field_presence = "LEGACY_REQUIRED";
2267
2246
  }
2268
- if (this.resolvedType instanceof Type && this.resolvedType.group) {
2269
- features.message_encoding = "DELIMITED";
2247
+ if (this.parent && types.defaults[this.type] === undefined) {
2248
+ // We can't use resolvedType because types may not have been resolved yet. However,
2249
+ // legacy groups are always in the same scope as the field so we don't have to do a
2250
+ // full scan of the tree.
2251
+ var type = this.parent.get(this.type.split(".").pop());
2252
+ if (type && type instanceof Type && type.group) {
2253
+ features.message_encoding = "DELIMITED";
2254
+ }
2270
2255
  }
2271
2256
  if (this.getOption("packed") === true) {
2272
2257
  features.repeated_field_encoding = "PACKED";
@@ -2438,7 +2423,7 @@ protobuf.types = require(32);
2438
2423
  protobuf.util = require(33);
2439
2424
 
2440
2425
  // Set up possibly cyclic reflection dependencies
2441
- protobuf.ReflectionObject._configure(protobuf.Root, protobuf.Namespace);
2426
+ protobuf.ReflectionObject._configure(protobuf.Root);
2442
2427
  protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
2443
2428
  protobuf.Root._configure(protobuf.Type);
2444
2429
  protobuf.Field._configure(protobuf.Type);
@@ -3238,7 +3223,7 @@ Namespace.prototype.resolveAll = function resolveAll() {
3238
3223
  * @override
3239
3224
  */
3240
3225
  Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
3241
- var edition = this._edition || edition;
3226
+ edition = this._edition || edition;
3242
3227
 
3243
3228
  ReflectionObject.prototype._resolveFeaturesRecursive.call(this, edition);
3244
3229
  this.nestedArray.forEach(nested => {
@@ -3378,7 +3363,7 @@ ReflectionObject.className = "ReflectionObject";
3378
3363
  const OneOf = require(23);
3379
3364
  var util = require(33);
3380
3365
 
3381
- var Root, Namespace; // cyclic
3366
+ var Root; // cyclic
3382
3367
 
3383
3368
  /* eslint-disable no-warning-comments */
3384
3369
  // TODO: Replace with embedded proto.
@@ -3439,6 +3424,12 @@ function ReflectionObject(name, options) {
3439
3424
  */
3440
3425
  this._features = {};
3441
3426
 
3427
+ /**
3428
+ * Whether or not features have been resolved.
3429
+ * @type {boolean}
3430
+ * /
3431
+ this._featuresResolved = false;
3432
+
3442
3433
  /**
3443
3434
  * Parent namespace.
3444
3435
  * @type {Namespace|null}
@@ -3545,7 +3536,6 @@ ReflectionObject.prototype.resolve = function resolve() {
3545
3536
  if (this.resolved)
3546
3537
  return this;
3547
3538
  if (this instanceof Root) {
3548
- this._resolveFeaturesRecursive(this._edition);
3549
3539
  this.resolved = true;
3550
3540
  }
3551
3541
  return this;
@@ -3566,8 +3556,13 @@ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeatures
3566
3556
  * @returns {undefined}
3567
3557
  */
3568
3558
  ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
3559
+ if (this._featuresResolved) {
3560
+ return;
3561
+ }
3562
+
3569
3563
  var defaults = {};
3570
3564
 
3565
+ /* istanbul ignore if */
3571
3566
  if (!edition) {
3572
3567
  throw new Error("Unknown edition for " + this.fullName);
3573
3568
  }
@@ -3577,6 +3572,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3577
3572
 
3578
3573
  if (this._edition) {
3579
3574
  // For a namespace marked with a specific edition, reset defaults.
3575
+ /* istanbul ignore else */
3580
3576
  if (edition === "proto2") {
3581
3577
  defaults = Object.assign({}, proto2Defaults);
3582
3578
  } else if (edition === "proto3") {
@@ -3587,11 +3583,13 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3587
3583
  throw new Error("Unknown edition: " + edition);
3588
3584
  }
3589
3585
  this._features = Object.assign(defaults, protoFeatures || {});
3586
+ this._featuresResolved = true;
3590
3587
  return;
3591
3588
  }
3592
3589
 
3593
3590
  // fields in Oneofs aren't actually children of them, so we have to
3594
3591
  // special-case it
3592
+ /* istanbul ignore else */
3595
3593
  if (this.partOf instanceof OneOf) {
3596
3594
  var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
3597
3595
  this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
@@ -3601,12 +3599,13 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3601
3599
  var parentFeaturesCopy = Object.assign({}, this.parent._features);
3602
3600
  this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
3603
3601
  } else {
3604
- this._features = Object.assign({}, protoFeatures);
3602
+ throw new Error("Unable to find a parent for " + this.fullName);
3605
3603
  }
3606
3604
  if (this.extensionField) {
3607
3605
  // Sister fields should have the same features as their extensions.
3608
3606
  this.extensionField._features = this._features;
3609
3607
  }
3608
+ this._featuresResolved = true;
3610
3609
  };
3611
3610
 
3612
3611
  /**
@@ -3640,13 +3639,7 @@ ReflectionObject.prototype.getOption = function getOption(name) {
3640
3639
  ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
3641
3640
  if (!this.options)
3642
3641
  this.options = {};
3643
- if (name === "features") {
3644
- if (ifNotSet) {
3645
- this.options.features = Object.assign(Object.assign({}, value), this.options.features || {});
3646
- } else {
3647
- this.options.features = Object.assign(this.options.features || {}, value);
3648
- }
3649
- } else if (/^features\./.test(name)) {
3642
+ if (/^features\./.test(name)) {
3650
3643
  util.setProperty(this.options, name, value, ifNotSet);
3651
3644
  } else if (!ifNotSet || this.options[name] === undefined) {
3652
3645
  if (this.getOption(name) !== value) this.resolved = false;
@@ -3667,7 +3660,6 @@ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, valu
3667
3660
  if (!this.parsedOptions) {
3668
3661
  this.parsedOptions = [];
3669
3662
  }
3670
- var isFeature = /^features$/.test(name);
3671
3663
  var parsedOptions = this.parsedOptions;
3672
3664
  if (propName) {
3673
3665
  // If setting a sub property of an option then try to merge it
@@ -3732,12 +3724,11 @@ ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
3732
3724
  return undefined;
3733
3725
  }
3734
3726
  return this._edition;
3735
- }
3727
+ };
3736
3728
 
3737
3729
  // Sets up cyclic dependencies (called in index-light)
3738
- ReflectionObject._configure = function(Root_, Namespace_) {
3730
+ ReflectionObject._configure = function(Root_) {
3739
3731
  Root = Root_;
3740
- Namespace = Namespace_;
3741
3732
  };
3742
3733
 
3743
3734
  },{"23":23,"33":33}],23:[function(require,module,exports){
@@ -4489,7 +4480,7 @@ Root.fromJSON = function fromJSON(json, root) {
4489
4480
  root = new Root();
4490
4481
  if (json.options)
4491
4482
  root.setOptions(json.options);
4492
- return root.addJSON(json.nested).resolveAll();
4483
+ return root.addJSON(json.nested)._resolveFeaturesRecursive();
4493
4484
  };
4494
4485
 
4495
4486
  /**
@@ -4537,6 +4528,9 @@ Root.prototype.load = function load(filename, options, callback) {
4537
4528
 
4538
4529
  // Finishes loading by calling the callback (exactly once)
4539
4530
  function finish(err, root) {
4531
+ if (root) {
4532
+ root._resolveFeaturesRecursive();
4533
+ }
4540
4534
  /* istanbul ignore if */
4541
4535
  if (!callback) {
4542
4536
  return;
@@ -4546,9 +4540,6 @@ Root.prototype.load = function load(filename, options, callback) {
4546
4540
  }
4547
4541
  var cb = callback;
4548
4542
  callback = null;
4549
- if (root) {
4550
- root.resolveAll();
4551
- }
4552
4543
  cb(err, root);
4553
4544
  }
4554
4545
 
@@ -4656,8 +4647,8 @@ Root.prototype.load = function load(filename, options, callback) {
4656
4647
  for (var i = 0, resolved; i < filename.length; ++i)
4657
4648
  if (resolved = self.resolvePath("", filename[i]))
4658
4649
  fetch(resolved);
4659
- self.resolveAll();
4660
4650
  if (sync) {
4651
+ self._resolveFeaturesRecursive();
4661
4652
  return self;
4662
4653
  }
4663
4654
  if (!queued) {
@@ -4710,6 +4701,7 @@ Root.prototype.resolveAll = function resolveAll() {
4710
4701
  throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
4711
4702
  return "'extend " + field.extend + "' in " + field.parent.fullName;
4712
4703
  }).join(", "));
4704
+ this._resolveFeaturesRecursive(this._edition);
4713
4705
  return Namespace.prototype.resolveAll.call(this);
4714
4706
  };
4715
4707
 
@@ -5147,11 +5139,11 @@ Service.prototype.resolveAll = function resolveAll() {
5147
5139
  * @override
5148
5140
  */
5149
5141
  Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
5150
- var edition = this._edition || edition;
5142
+ edition = this._edition || edition;
5151
5143
 
5152
5144
  Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
5153
5145
  this.methodsArray.forEach(method => {
5154
- method._resolveFeaturesRecursive(edition);
5146
+ method._resolveFeaturesRecursive(edition);
5155
5147
  });
5156
5148
  return this;
5157
5149
  };
@@ -5447,7 +5439,7 @@ function clearCache(type) {
5447
5439
  * @param {IType} json Message type descriptor
5448
5440
  * @returns {Type} Created message type
5449
5441
  */
5450
- Type.fromJSON = function fromJSON(name, json, nested) {
5442
+ Type.fromJSON = function fromJSON(name, json) {
5451
5443
  var type = new Type(name, json.options);
5452
5444
  type.extensions = json.extensions;
5453
5445
  type.reserved = json.reserved;
@@ -5530,14 +5522,14 @@ Type.prototype.resolveAll = function resolveAll() {
5530
5522
  * @override
5531
5523
  */
5532
5524
  Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
5533
- var edition = this._edition || edition;
5525
+ edition = this._edition || edition;
5534
5526
 
5535
5527
  Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
5536
5528
  this.oneofsArray.forEach(oneof => {
5537
- oneof._resolveFeatures(edition);
5529
+ oneof._resolveFeatures(edition);
5538
5530
  });
5539
5531
  this.fieldsArray.forEach(field => {
5540
- field._resolveFeatures(edition);
5532
+ field._resolveFeatures(edition);
5541
5533
  });
5542
5534
  return this;
5543
5535
  };