protobufjs 7.5.1 → 7.5.3

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 v7.5.1 (c) 2016, daniel wirtz
3
- * compiled thu, 08 may 2025 17:34:56 utc
2
+ * protobuf.js v7.5.3 (c) 2016, daniel wirtz
3
+ * compiled wed, 28 may 2025 22:23:47 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 v7.5.1 (c) 2016, daniel wirtz
3
- * compiled thu, 08 may 2025 17:34:56 utc
2
+ * protobuf.js v7.5.3 (c) 2016, daniel wirtz
3
+ * compiled wed, 28 may 2025 22:23:47 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 v7.5.1 (c) 2016, daniel wirtz
3
- * compiled thu, 08 may 2025 17:34:56 utc
2
+ * protobuf.js v7.5.3 (c) 2016, daniel wirtz
3
+ * compiled wed, 28 may 2025 22:23:47 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -3438,6 +3438,13 @@ function Namespace(name, options) {
3438
3438
  * @protected
3439
3439
  */
3440
3440
  this._needsRecursiveFeatureResolution = true;
3441
+
3442
+ /**
3443
+ * Whether or not objects contained in this namespace need a resolve.
3444
+ * @type {boolean}
3445
+ * @protected
3446
+ */
3447
+ this._needsRecursiveResolve = true;
3441
3448
  }
3442
3449
 
3443
3450
  function clearCache(namespace) {
@@ -3587,11 +3594,13 @@ Namespace.prototype.add = function add(object) {
3587
3594
  }
3588
3595
 
3589
3596
  this._needsRecursiveFeatureResolution = true;
3597
+ this._needsRecursiveResolve = true;
3590
3598
 
3591
3599
  // Also clear parent caches, since they need to recurse down.
3592
3600
  var parent = this;
3593
3601
  while(parent = parent.parent) {
3594
3602
  parent._needsRecursiveFeatureResolution = true;
3603
+ parent._needsRecursiveResolve = true;
3595
3604
  }
3596
3605
 
3597
3606
  object.onAdd(this);
@@ -3655,6 +3664,10 @@ Namespace.prototype.define = function define(path, json) {
3655
3664
  * @returns {Namespace} `this`
3656
3665
  */
3657
3666
  Namespace.prototype.resolveAll = function resolveAll() {
3667
+ if (!this._needsRecursiveResolve) return this;
3668
+
3669
+ this._resolveFeaturesRecursive(this._edition);
3670
+
3658
3671
  var nested = this.nestedArray, i = 0;
3659
3672
  this.resolve();
3660
3673
  while (i < nested.length)
@@ -3662,6 +3675,7 @@ Namespace.prototype.resolveAll = function resolveAll() {
3662
3675
  nested[i++].resolveAll();
3663
3676
  else
3664
3677
  nested[i++].resolve();
3678
+ this._needsRecursiveResolve = false;
3665
3679
  return this;
3666
3680
  };
3667
3681
 
@@ -3703,29 +3717,47 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
3703
3717
  } else if (!path.length)
3704
3718
  return this;
3705
3719
 
3720
+ var flatPath = path.join(".");
3721
+
3706
3722
  // Start at root if path is absolute
3707
3723
  if (path[0] === "")
3708
3724
  return this.root.lookup(path.slice(1), filterTypes);
3709
3725
 
3710
- var found = this._lookupImpl(path);
3726
+ // Early bailout for objects with matching absolute paths
3727
+ var found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
3728
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3729
+ return found;
3730
+ }
3731
+
3732
+ // Do a regular lookup at this namespace and below
3733
+ found = this._lookupImpl(path, flatPath);
3711
3734
  if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3712
3735
  return found;
3713
3736
  }
3714
3737
 
3715
- // If there hasn't been a match, try again at the parent
3716
- if (this.parent === null || parentAlreadyChecked)
3738
+ if (parentAlreadyChecked)
3717
3739
  return null;
3718
- return this.parent.lookup(path, filterTypes);
3740
+
3741
+ // If there hasn't been a match, walk up the tree and look more broadly
3742
+ var current = this;
3743
+ while (current.parent) {
3744
+ found = current.parent._lookupImpl(path, flatPath);
3745
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3746
+ return found;
3747
+ }
3748
+ current = current.parent;
3749
+ }
3750
+ return null;
3719
3751
  };
3720
3752
 
3721
3753
  /**
3722
3754
  * Internal helper for lookup that handles searching just at this namespace and below along with caching.
3723
3755
  * @param {string[]} path Path to look up
3756
+ * @param {string} flatPath Flattened version of the path to use as a cache key
3724
3757
  * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
3725
3758
  * @private
3726
3759
  */
3727
- Namespace.prototype._lookupImpl = function lookup(path) {
3728
- var flatPath = path.join(".");
3760
+ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
3729
3761
  if(Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
3730
3762
  return this._lookupCache[flatPath];
3731
3763
  }
@@ -3736,13 +3768,15 @@ Namespace.prototype._lookupImpl = function lookup(path) {
3736
3768
  if (found) {
3737
3769
  if (path.length === 1) {
3738
3770
  exact = found;
3739
- } else if (found instanceof Namespace && (found = found._lookupImpl(path.slice(1))))
3740
- exact = found;
3771
+ } else if (found instanceof Namespace) {
3772
+ path = path.slice(1);
3773
+ exact = found._lookupImpl(path, path.join("."));
3774
+ }
3741
3775
 
3742
3776
  // Otherwise try each nested namespace
3743
3777
  } else {
3744
3778
  for (var i = 0; i < this.nestedArray.length; ++i)
3745
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path)))
3779
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
3746
3780
  exact = found;
3747
3781
  }
3748
3782
 
@@ -3879,6 +3913,7 @@ function ReflectionObject(name, options) {
3879
3913
  /**
3880
3914
  * The edition specified for this object. Only relevant for top-level objects.
3881
3915
  * @type {string}
3916
+ * @private
3882
3917
  */
3883
3918
  this._edition = null;
3884
3919
 
@@ -3886,18 +3921,21 @@ function ReflectionObject(name, options) {
3886
3921
  * The default edition to use for this object if none is specified. For legacy reasons,
3887
3922
  * this is proto2 except in the JSON parsing case where it was proto3.
3888
3923
  * @type {string}
3924
+ * @private
3889
3925
  */
3890
3926
  this._defaultEdition = "proto2";
3891
3927
 
3892
3928
  /**
3893
3929
  * Resolved Features.
3894
3930
  * @type {object}
3931
+ * @private
3895
3932
  */
3896
3933
  this._features = {};
3897
3934
 
3898
3935
  /**
3899
3936
  * Whether or not features have been resolved.
3900
3937
  * @type {boolean}
3938
+ * @private
3901
3939
  */
3902
3940
  this._featuresResolved = false;
3903
3941
 
@@ -5906,8 +5944,19 @@ function Root(options) {
5906
5944
  */
5907
5945
  this.files = [];
5908
5946
 
5909
- // Default to proto2 if unspecified.
5947
+ /**
5948
+ * Edition, defaults to proto2 if unspecified.
5949
+ * @type {string}
5950
+ * @private
5951
+ */
5910
5952
  this._edition = "proto2";
5953
+
5954
+ /**
5955
+ * Global lookup cache of fully qualified names.
5956
+ * @type {Object.<string,ReflectionObject>}
5957
+ * @private
5958
+ */
5959
+ this._fullyQualifiedObjects = {};
5911
5960
  }
5912
5961
 
5913
5962
  /**
@@ -5921,7 +5970,7 @@ Root.fromJSON = function fromJSON(json, root) {
5921
5970
  root = new Root();
5922
5971
  if (json.options)
5923
5972
  root.setOptions(json.options);
5924
- return root.addJSON(json.nested)._resolveFeaturesRecursive();
5973
+ return root.addJSON(json.nested).resolveAll();
5925
5974
  };
5926
5975
 
5927
5976
  /**
@@ -5969,9 +6018,6 @@ Root.prototype.load = function load(filename, options, callback) {
5969
6018
 
5970
6019
  // Finishes loading by calling the callback (exactly once)
5971
6020
  function finish(err, root) {
5972
- if (root) {
5973
- root._resolveFeaturesRecursive();
5974
- }
5975
6021
  /* istanbul ignore if */
5976
6022
  if (!callback) {
5977
6023
  return;
@@ -5979,6 +6025,9 @@ Root.prototype.load = function load(filename, options, callback) {
5979
6025
  if (sync) {
5980
6026
  throw err;
5981
6027
  }
6028
+ if (root) {
6029
+ root.resolveAll();
6030
+ }
5982
6031
  var cb = callback;
5983
6032
  callback = null;
5984
6033
  cb(err, root);
@@ -6089,7 +6138,7 @@ Root.prototype.load = function load(filename, options, callback) {
6089
6138
  if (resolved = self.resolvePath("", filename[i]))
6090
6139
  fetch(resolved);
6091
6140
  if (sync) {
6092
- self._resolveFeaturesRecursive();
6141
+ self.resolveAll();
6093
6142
  return self;
6094
6143
  }
6095
6144
  if (!queued) {
@@ -6138,11 +6187,12 @@ Root.prototype.loadSync = function loadSync(filename, options) {
6138
6187
  * @override
6139
6188
  */
6140
6189
  Root.prototype.resolveAll = function resolveAll() {
6190
+ if (!this._needsRecursiveResolve) return this;
6191
+
6141
6192
  if (this.deferred.length)
6142
6193
  throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
6143
6194
  return "'extend " + field.extend + "' in " + field.parent.fullName;
6144
6195
  }).join(", "));
6145
- this._resolveFeaturesRecursive(this._edition);
6146
6196
  return Namespace.prototype.resolveAll.call(this);
6147
6197
  };
6148
6198
 
@@ -6205,6 +6255,11 @@ Root.prototype._handleAdd = function _handleAdd(object) {
6205
6255
  object.parent[object.name] = object; // expose namespace as property of its parent
6206
6256
  }
6207
6257
 
6258
+ if (object instanceof Type || object instanceof Enum || object instanceof Field) {
6259
+ // Only store types and enums for quick lookup during resolve.
6260
+ this._fullyQualifiedObjects[object.fullName] = object;
6261
+ }
6262
+
6208
6263
  // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
6209
6264
  // properties of namespaces just like static code does. This allows using a .d.ts generated for
6210
6265
  // a static module with reflection-based solutions where the condition is met.
@@ -6245,6 +6300,8 @@ Root.prototype._handleRemove = function _handleRemove(object) {
6245
6300
  delete object.parent[object.name]; // unexpose namespaces
6246
6301
 
6247
6302
  }
6303
+
6304
+ delete this._fullyQualifiedObjects[object.fullName];
6248
6305
  };
6249
6306
 
6250
6307
  // Sets up cyclic dependencies (called in index-light)
@@ -6569,6 +6626,8 @@ Service.prototype.get = function get(name) {
6569
6626
  * @override
6570
6627
  */
6571
6628
  Service.prototype.resolveAll = function resolveAll() {
6629
+ if (!this._needsRecursiveResolve) return this;
6630
+
6572
6631
  Namespace.prototype.resolve.call(this);
6573
6632
  var methods = this.methodsArray;
6574
6633
  for (var i = 0; i < methods.length; ++i)
@@ -7369,6 +7428,8 @@ Type.prototype.toJSON = function toJSON(toJSONOptions) {
7369
7428
  * @override
7370
7429
  */
7371
7430
  Type.prototype.resolveAll = function resolveAll() {
7431
+ if (!this._needsRecursiveResolve) return this;
7432
+
7372
7433
  Namespace.prototype.resolveAll.call(this);
7373
7434
  var oneofs = this.oneofsArray; i = 0;
7374
7435
  while (i < oneofs.length)