protobufjs 8.0.4-experimental → 8.1.0-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.0-experimental (c) 2016, daniel wirtz
3
+ * compiled wed, 07 may 2025 17:43:49 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.
@@ -3568,6 +3553,7 @@ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeatures
3568
3553
  ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
3569
3554
  var defaults = {};
3570
3555
 
3556
+ /* istanbul ignore if */
3571
3557
  if (!edition) {
3572
3558
  throw new Error("Unknown edition for " + this.fullName);
3573
3559
  }
@@ -3577,6 +3563,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3577
3563
 
3578
3564
  if (this._edition) {
3579
3565
  // For a namespace marked with a specific edition, reset defaults.
3566
+ /* istanbul ignore else */
3580
3567
  if (edition === "proto2") {
3581
3568
  defaults = Object.assign({}, proto2Defaults);
3582
3569
  } else if (edition === "proto3") {
@@ -3592,6 +3579,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3592
3579
 
3593
3580
  // fields in Oneofs aren't actually children of them, so we have to
3594
3581
  // special-case it
3582
+ /* istanbul ignore else */
3595
3583
  if (this.partOf instanceof OneOf) {
3596
3584
  var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
3597
3585
  this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
@@ -3601,7 +3589,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3601
3589
  var parentFeaturesCopy = Object.assign({}, this.parent._features);
3602
3590
  this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
3603
3591
  } else {
3604
- this._features = Object.assign({}, protoFeatures);
3592
+ throw new Error("Unable to find a parent for " + this.fullName);
3605
3593
  }
3606
3594
  if (this.extensionField) {
3607
3595
  // Sister fields should have the same features as their extensions.
@@ -3640,13 +3628,7 @@ ReflectionObject.prototype.getOption = function getOption(name) {
3640
3628
  ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
3641
3629
  if (!this.options)
3642
3630
  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)) {
3631
+ if (/^features\./.test(name)) {
3650
3632
  util.setProperty(this.options, name, value, ifNotSet);
3651
3633
  } else if (!ifNotSet || this.options[name] === undefined) {
3652
3634
  if (this.getOption(name) !== value) this.resolved = false;
@@ -3667,7 +3649,6 @@ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, valu
3667
3649
  if (!this.parsedOptions) {
3668
3650
  this.parsedOptions = [];
3669
3651
  }
3670
- var isFeature = /^features$/.test(name);
3671
3652
  var parsedOptions = this.parsedOptions;
3672
3653
  if (propName) {
3673
3654
  // If setting a sub property of an option then try to merge it
@@ -3732,12 +3713,11 @@ ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
3732
3713
  return undefined;
3733
3714
  }
3734
3715
  return this._edition;
3735
- }
3716
+ };
3736
3717
 
3737
3718
  // Sets up cyclic dependencies (called in index-light)
3738
- ReflectionObject._configure = function(Root_, Namespace_) {
3719
+ ReflectionObject._configure = function(Root_) {
3739
3720
  Root = Root_;
3740
- Namespace = Namespace_;
3741
3721
  };
3742
3722
 
3743
3723
  },{"23":23,"33":33}],23:[function(require,module,exports){
@@ -4489,7 +4469,7 @@ Root.fromJSON = function fromJSON(json, root) {
4489
4469
  root = new Root();
4490
4470
  if (json.options)
4491
4471
  root.setOptions(json.options);
4492
- return root.addJSON(json.nested).resolveAll();
4472
+ return root.addJSON(json.nested)._resolveFeaturesRecursive();
4493
4473
  };
4494
4474
 
4495
4475
  /**
@@ -4537,6 +4517,9 @@ Root.prototype.load = function load(filename, options, callback) {
4537
4517
 
4538
4518
  // Finishes loading by calling the callback (exactly once)
4539
4519
  function finish(err, root) {
4520
+ if (root) {
4521
+ root._resolveFeaturesRecursive();
4522
+ }
4540
4523
  /* istanbul ignore if */
4541
4524
  if (!callback) {
4542
4525
  return;
@@ -4546,9 +4529,6 @@ Root.prototype.load = function load(filename, options, callback) {
4546
4529
  }
4547
4530
  var cb = callback;
4548
4531
  callback = null;
4549
- if (root) {
4550
- root.resolveAll();
4551
- }
4552
4532
  cb(err, root);
4553
4533
  }
4554
4534
 
@@ -4656,8 +4636,8 @@ Root.prototype.load = function load(filename, options, callback) {
4656
4636
  for (var i = 0, resolved; i < filename.length; ++i)
4657
4637
  if (resolved = self.resolvePath("", filename[i]))
4658
4638
  fetch(resolved);
4659
- self.resolveAll();
4660
4639
  if (sync) {
4640
+ self._resolveFeaturesRecursive();
4661
4641
  return self;
4662
4642
  }
4663
4643
  if (!queued) {
@@ -5147,11 +5127,11 @@ Service.prototype.resolveAll = function resolveAll() {
5147
5127
  * @override
5148
5128
  */
5149
5129
  Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
5150
- var edition = this._edition || edition;
5130
+ edition = this._edition || edition;
5151
5131
 
5152
5132
  Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
5153
5133
  this.methodsArray.forEach(method => {
5154
- method._resolveFeaturesRecursive(edition);
5134
+ method._resolveFeaturesRecursive(edition);
5155
5135
  });
5156
5136
  return this;
5157
5137
  };
@@ -5447,7 +5427,7 @@ function clearCache(type) {
5447
5427
  * @param {IType} json Message type descriptor
5448
5428
  * @returns {Type} Created message type
5449
5429
  */
5450
- Type.fromJSON = function fromJSON(name, json, nested) {
5430
+ Type.fromJSON = function fromJSON(name, json) {
5451
5431
  var type = new Type(name, json.options);
5452
5432
  type.extensions = json.extensions;
5453
5433
  type.reserved = json.reserved;
@@ -5530,14 +5510,14 @@ Type.prototype.resolveAll = function resolveAll() {
5530
5510
  * @override
5531
5511
  */
5532
5512
  Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
5533
- var edition = this._edition || edition;
5513
+ edition = this._edition || edition;
5534
5514
 
5535
5515
  Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
5536
5516
  this.oneofsArray.forEach(oneof => {
5537
- oneof._resolveFeatures(edition);
5517
+ oneof._resolveFeatures(edition);
5538
5518
  });
5539
5519
  this.fieldsArray.forEach(field => {
5540
- field._resolveFeatures(edition);
5520
+ field._resolveFeatures(edition);
5541
5521
  });
5542
5522
  return this;
5543
5523
  };