protobufjs 8.1.0-experimental → 8.1.2-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.1.0-experimental (c) 2016, daniel wirtz
3
- * compiled wed, 07 may 2025 17:43:49 utc
2
+ * protobuf.js v8.1.2-experimental (c) 2016, daniel wirtz
3
+ * compiled thu, 08 may 2025 17:02:50 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -3007,10 +3007,33 @@ function Namespace(name, options) {
3007
3007
  * @private
3008
3008
  */
3009
3009
  this._nestedArray = null;
3010
+
3011
+ /**
3012
+ * Cache lookup calls for any objects contains anywhere under this namespace.
3013
+ * This drastically speeds up resolve for large cross-linked protos where the same
3014
+ * types are looked up repeatedly.
3015
+ * @type {Object.<string,ReflectionObject|null>}
3016
+ * @private
3017
+ */
3018
+ this._lookupCache = {};
3019
+
3020
+ /**
3021
+ * Whether or not objects contained in this namespace need feature resolution.
3022
+ * @type {boolean}
3023
+ * @protected
3024
+ */
3025
+ this._needsRecursiveFeatureResolution = true;
3010
3026
  }
3011
3027
 
3012
3028
  function clearCache(namespace) {
3013
3029
  namespace._nestedArray = null;
3030
+ namespace._lookupCache = {};
3031
+
3032
+ // Also clear parent caches, since they include nested lookups.
3033
+ var parent = namespace;
3034
+ while(parent = parent.parent) {
3035
+ parent._lookupCache = {};
3036
+ }
3014
3037
  return namespace;
3015
3038
  }
3016
3039
 
@@ -3148,6 +3171,14 @@ Namespace.prototype.add = function add(object) {
3148
3171
  }
3149
3172
  }
3150
3173
 
3174
+ this._needsRecursiveFeatureResolution = true;
3175
+
3176
+ // Also clear parent caches, since they need to recurse down.
3177
+ var parent = this;
3178
+ while(parent = parent.parent) {
3179
+ parent._needsRecursiveFeatureResolution = true;
3180
+ }
3181
+
3151
3182
  object.onAdd(this);
3152
3183
  return clearCache(this);
3153
3184
  };
@@ -3223,6 +3254,9 @@ Namespace.prototype.resolveAll = function resolveAll() {
3223
3254
  * @override
3224
3255
  */
3225
3256
  Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
3257
+ if (!this._needsRecursiveFeatureResolution) return this;
3258
+ this._needsRecursiveFeatureResolution = false;
3259
+
3226
3260
  edition = this._edition || edition;
3227
3261
 
3228
3262
  ReflectionObject.prototype._resolveFeaturesRecursive.call(this, edition);
@@ -3240,7 +3274,6 @@ Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursi
3240
3274
  * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
3241
3275
  */
3242
3276
  Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {
3243
-
3244
3277
  /* istanbul ignore next */
3245
3278
  if (typeof filterTypes === "boolean") {
3246
3279
  parentAlreadyChecked = filterTypes;
@@ -3259,25 +3292,48 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
3259
3292
  if (path[0] === "")
3260
3293
  return this.root.lookup(path.slice(1), filterTypes);
3261
3294
 
3295
+ var found = this._lookupImpl(path);
3296
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3297
+ return found;
3298
+ }
3299
+
3300
+ // If there hasn't been a match, try again at the parent
3301
+ if (this.parent === null || parentAlreadyChecked)
3302
+ return null;
3303
+ return this.parent.lookup(path, filterTypes);
3304
+ };
3305
+
3306
+ /**
3307
+ * Internal helper for lookup that handles searching just at this namespace and below along with caching.
3308
+ * @param {string[]} path Path to look up
3309
+ * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
3310
+ * @private
3311
+ */
3312
+ Namespace.prototype._lookupImpl = function lookup(path) {
3313
+ var flatPath = path.join(".");
3314
+ if(Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
3315
+ return this._lookupCache[flatPath];
3316
+ }
3317
+
3262
3318
  // Test if the first part matches any nested object, and if so, traverse if path contains more
3263
3319
  var found = this.get(path[0]);
3320
+ var exact = null;
3264
3321
  if (found) {
3265
3322
  if (path.length === 1) {
3266
- if (!filterTypes || filterTypes.indexOf(found.constructor) > -1)
3267
- return found;
3268
- } else if (found instanceof Namespace && (found = found.lookup(path.slice(1), filterTypes, true)))
3269
- return found;
3323
+ exact = found;
3324
+ } else if (found instanceof Namespace && (found = found._lookupImpl(path.slice(1))))
3325
+ exact = found;
3270
3326
 
3271
3327
  // Otherwise try each nested namespace
3272
- } else
3328
+ } else {
3273
3329
  for (var i = 0; i < this.nestedArray.length; ++i)
3274
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].lookup(path, filterTypes, true)))
3275
- return found;
3330
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path)))
3331
+ exact = found;
3332
+ }
3276
3333
 
3277
- // If there hasn't been a match, try again at the parent
3278
- if (this.parent === null || parentAlreadyChecked)
3279
- return null;
3280
- return this.parent.lookup(path, filterTypes);
3334
+ // Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
3335
+ this._lookupCache[flatPath] = exact;
3336
+ return exact;
3281
3337
  };
3282
3338
 
3283
3339
  /**
@@ -3424,6 +3480,12 @@ function ReflectionObject(name, options) {
3424
3480
  */
3425
3481
  this._features = {};
3426
3482
 
3483
+ /**
3484
+ * Whether or not features have been resolved.
3485
+ * @type {boolean}
3486
+ */
3487
+ this._featuresResolved = false;
3488
+
3427
3489
  /**
3428
3490
  * Parent namespace.
3429
3491
  * @type {Namespace|null}
@@ -3529,10 +3591,8 @@ ReflectionObject.prototype.onRemove = function onRemove(parent) {
3529
3591
  ReflectionObject.prototype.resolve = function resolve() {
3530
3592
  if (this.resolved)
3531
3593
  return this;
3532
- if (this instanceof Root) {
3533
- this._resolveFeaturesRecursive(this._edition);
3534
- this.resolved = true;
3535
- }
3594
+ if (this.root instanceof Root)
3595
+ this.resolved = true; // only if part of a root
3536
3596
  return this;
3537
3597
  };
3538
3598
 
@@ -3551,6 +3611,10 @@ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeatures
3551
3611
  * @returns {undefined}
3552
3612
  */
3553
3613
  ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
3614
+ if (this._featuresResolved) {
3615
+ return;
3616
+ }
3617
+
3554
3618
  var defaults = {};
3555
3619
 
3556
3620
  /* istanbul ignore if */
@@ -3574,6 +3638,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3574
3638
  throw new Error("Unknown edition: " + edition);
3575
3639
  }
3576
3640
  this._features = Object.assign(defaults, protoFeatures || {});
3641
+ this._featuresResolved = true;
3577
3642
  return;
3578
3643
  }
3579
3644
 
@@ -3595,6 +3660,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3595
3660
  // Sister fields should have the same features as their extensions.
3596
3661
  this.extensionField._features = this._features;
3597
3662
  }
3663
+ this._featuresResolved = true;
3598
3664
  };
3599
3665
 
3600
3666
  /**
@@ -4690,6 +4756,7 @@ Root.prototype.resolveAll = function resolveAll() {
4690
4756
  throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
4691
4757
  return "'extend " + field.extend + "' in " + field.parent.fullName;
4692
4758
  }).join(", "));
4759
+ this._resolveFeaturesRecursive(this._edition);
4693
4760
  return Namespace.prototype.resolveAll.call(this);
4694
4761
  };
4695
4762
 
@@ -5127,6 +5194,8 @@ Service.prototype.resolveAll = function resolveAll() {
5127
5194
  * @override
5128
5195
  */
5129
5196
  Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
5197
+ if (!this._needsRecursiveFeatureResolution) return this;
5198
+
5130
5199
  edition = this._edition || edition;
5131
5200
 
5132
5201
  Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
@@ -5510,6 +5579,8 @@ Type.prototype.resolveAll = function resolveAll() {
5510
5579
  * @override
5511
5580
  */
5512
5581
  Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
5582
+ if (!this._needsRecursiveFeatureResolution) return this;
5583
+
5513
5584
  edition = this._edition || edition;
5514
5585
 
5515
5586
  Namespace.prototype._resolveFeaturesRecursive.call(this, edition);