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
  */
@@ -3023,6 +3023,13 @@ function Namespace(name, options) {
3023
3023
  * @protected
3024
3024
  */
3025
3025
  this._needsRecursiveFeatureResolution = true;
3026
+
3027
+ /**
3028
+ * Whether or not objects contained in this namespace need a resolve.
3029
+ * @type {boolean}
3030
+ * @protected
3031
+ */
3032
+ this._needsRecursiveResolve = true;
3026
3033
  }
3027
3034
 
3028
3035
  function clearCache(namespace) {
@@ -3172,11 +3179,13 @@ Namespace.prototype.add = function add(object) {
3172
3179
  }
3173
3180
 
3174
3181
  this._needsRecursiveFeatureResolution = true;
3182
+ this._needsRecursiveResolve = true;
3175
3183
 
3176
3184
  // Also clear parent caches, since they need to recurse down.
3177
3185
  var parent = this;
3178
3186
  while(parent = parent.parent) {
3179
3187
  parent._needsRecursiveFeatureResolution = true;
3188
+ parent._needsRecursiveResolve = true;
3180
3189
  }
3181
3190
 
3182
3191
  object.onAdd(this);
@@ -3240,6 +3249,10 @@ Namespace.prototype.define = function define(path, json) {
3240
3249
  * @returns {Namespace} `this`
3241
3250
  */
3242
3251
  Namespace.prototype.resolveAll = function resolveAll() {
3252
+ if (!this._needsRecursiveResolve) return this;
3253
+
3254
+ this._resolveFeaturesRecursive(this._edition);
3255
+
3243
3256
  var nested = this.nestedArray, i = 0;
3244
3257
  this.resolve();
3245
3258
  while (i < nested.length)
@@ -3247,6 +3260,7 @@ Namespace.prototype.resolveAll = function resolveAll() {
3247
3260
  nested[i++].resolveAll();
3248
3261
  else
3249
3262
  nested[i++].resolve();
3263
+ this._needsRecursiveResolve = false;
3250
3264
  return this;
3251
3265
  };
3252
3266
 
@@ -3288,29 +3302,47 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
3288
3302
  } else if (!path.length)
3289
3303
  return this;
3290
3304
 
3305
+ var flatPath = path.join(".");
3306
+
3291
3307
  // Start at root if path is absolute
3292
3308
  if (path[0] === "")
3293
3309
  return this.root.lookup(path.slice(1), filterTypes);
3294
3310
 
3295
- var found = this._lookupImpl(path);
3311
+ // Early bailout for objects with matching absolute paths
3312
+ var found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
3313
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3314
+ return found;
3315
+ }
3316
+
3317
+ // Do a regular lookup at this namespace and below
3318
+ found = this._lookupImpl(path, flatPath);
3296
3319
  if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3297
3320
  return found;
3298
3321
  }
3299
3322
 
3300
- // If there hasn't been a match, try again at the parent
3301
- if (this.parent === null || parentAlreadyChecked)
3323
+ if (parentAlreadyChecked)
3302
3324
  return null;
3303
- return this.parent.lookup(path, filterTypes);
3325
+
3326
+ // If there hasn't been a match, walk up the tree and look more broadly
3327
+ var current = this;
3328
+ while (current.parent) {
3329
+ found = current.parent._lookupImpl(path, flatPath);
3330
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
3331
+ return found;
3332
+ }
3333
+ current = current.parent;
3334
+ }
3335
+ return null;
3304
3336
  };
3305
3337
 
3306
3338
  /**
3307
3339
  * Internal helper for lookup that handles searching just at this namespace and below along with caching.
3308
3340
  * @param {string[]} path Path to look up
3341
+ * @param {string} flatPath Flattened version of the path to use as a cache key
3309
3342
  * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
3310
3343
  * @private
3311
3344
  */
3312
- Namespace.prototype._lookupImpl = function lookup(path) {
3313
- var flatPath = path.join(".");
3345
+ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
3314
3346
  if(Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
3315
3347
  return this._lookupCache[flatPath];
3316
3348
  }
@@ -3321,13 +3353,15 @@ Namespace.prototype._lookupImpl = function lookup(path) {
3321
3353
  if (found) {
3322
3354
  if (path.length === 1) {
3323
3355
  exact = found;
3324
- } else if (found instanceof Namespace && (found = found._lookupImpl(path.slice(1))))
3325
- exact = found;
3356
+ } else if (found instanceof Namespace) {
3357
+ path = path.slice(1);
3358
+ exact = found._lookupImpl(path, path.join("."));
3359
+ }
3326
3360
 
3327
3361
  // Otherwise try each nested namespace
3328
3362
  } else {
3329
3363
  for (var i = 0; i < this.nestedArray.length; ++i)
3330
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path)))
3364
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
3331
3365
  exact = found;
3332
3366
  }
3333
3367
 
@@ -3464,6 +3498,7 @@ function ReflectionObject(name, options) {
3464
3498
  /**
3465
3499
  * The edition specified for this object. Only relevant for top-level objects.
3466
3500
  * @type {string}
3501
+ * @private
3467
3502
  */
3468
3503
  this._edition = null;
3469
3504
 
@@ -3471,18 +3506,21 @@ function ReflectionObject(name, options) {
3471
3506
  * The default edition to use for this object if none is specified. For legacy reasons,
3472
3507
  * this is proto2 except in the JSON parsing case where it was proto3.
3473
3508
  * @type {string}
3509
+ * @private
3474
3510
  */
3475
3511
  this._defaultEdition = "proto2";
3476
3512
 
3477
3513
  /**
3478
3514
  * Resolved Features.
3479
3515
  * @type {object}
3516
+ * @private
3480
3517
  */
3481
3518
  this._features = {};
3482
3519
 
3483
3520
  /**
3484
3521
  * Whether or not features have been resolved.
3485
3522
  * @type {boolean}
3523
+ * @private
3486
3524
  */
3487
3525
  this._featuresResolved = false;
3488
3526
 
@@ -4520,8 +4558,19 @@ function Root(options) {
4520
4558
  */
4521
4559
  this.files = [];
4522
4560
 
4523
- // Default to proto2 if unspecified.
4561
+ /**
4562
+ * Edition, defaults to proto2 if unspecified.
4563
+ * @type {string}
4564
+ * @private
4565
+ */
4524
4566
  this._edition = "proto2";
4567
+
4568
+ /**
4569
+ * Global lookup cache of fully qualified names.
4570
+ * @type {Object.<string,ReflectionObject>}
4571
+ * @private
4572
+ */
4573
+ this._fullyQualifiedObjects = {};
4525
4574
  }
4526
4575
 
4527
4576
  /**
@@ -4535,7 +4584,7 @@ Root.fromJSON = function fromJSON(json, root) {
4535
4584
  root = new Root();
4536
4585
  if (json.options)
4537
4586
  root.setOptions(json.options);
4538
- return root.addJSON(json.nested)._resolveFeaturesRecursive();
4587
+ return root.addJSON(json.nested).resolveAll();
4539
4588
  };
4540
4589
 
4541
4590
  /**
@@ -4583,9 +4632,6 @@ Root.prototype.load = function load(filename, options, callback) {
4583
4632
 
4584
4633
  // Finishes loading by calling the callback (exactly once)
4585
4634
  function finish(err, root) {
4586
- if (root) {
4587
- root._resolveFeaturesRecursive();
4588
- }
4589
4635
  /* istanbul ignore if */
4590
4636
  if (!callback) {
4591
4637
  return;
@@ -4593,6 +4639,9 @@ Root.prototype.load = function load(filename, options, callback) {
4593
4639
  if (sync) {
4594
4640
  throw err;
4595
4641
  }
4642
+ if (root) {
4643
+ root.resolveAll();
4644
+ }
4596
4645
  var cb = callback;
4597
4646
  callback = null;
4598
4647
  cb(err, root);
@@ -4703,7 +4752,7 @@ Root.prototype.load = function load(filename, options, callback) {
4703
4752
  if (resolved = self.resolvePath("", filename[i]))
4704
4753
  fetch(resolved);
4705
4754
  if (sync) {
4706
- self._resolveFeaturesRecursive();
4755
+ self.resolveAll();
4707
4756
  return self;
4708
4757
  }
4709
4758
  if (!queued) {
@@ -4752,11 +4801,12 @@ Root.prototype.loadSync = function loadSync(filename, options) {
4752
4801
  * @override
4753
4802
  */
4754
4803
  Root.prototype.resolveAll = function resolveAll() {
4804
+ if (!this._needsRecursiveResolve) return this;
4805
+
4755
4806
  if (this.deferred.length)
4756
4807
  throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
4757
4808
  return "'extend " + field.extend + "' in " + field.parent.fullName;
4758
4809
  }).join(", "));
4759
- this._resolveFeaturesRecursive(this._edition);
4760
4810
  return Namespace.prototype.resolveAll.call(this);
4761
4811
  };
4762
4812
 
@@ -4819,6 +4869,11 @@ Root.prototype._handleAdd = function _handleAdd(object) {
4819
4869
  object.parent[object.name] = object; // expose namespace as property of its parent
4820
4870
  }
4821
4871
 
4872
+ if (object instanceof Type || object instanceof Enum || object instanceof Field) {
4873
+ // Only store types and enums for quick lookup during resolve.
4874
+ this._fullyQualifiedObjects[object.fullName] = object;
4875
+ }
4876
+
4822
4877
  // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
4823
4878
  // properties of namespaces just like static code does. This allows using a .d.ts generated for
4824
4879
  // a static module with reflection-based solutions where the condition is met.
@@ -4859,6 +4914,8 @@ Root.prototype._handleRemove = function _handleRemove(object) {
4859
4914
  delete object.parent[object.name]; // unexpose namespaces
4860
4915
 
4861
4916
  }
4917
+
4918
+ delete this._fullyQualifiedObjects[object.fullName];
4862
4919
  };
4863
4920
 
4864
4921
  // Sets up cyclic dependencies (called in index-light)
@@ -5183,6 +5240,8 @@ Service.prototype.get = function get(name) {
5183
5240
  * @override
5184
5241
  */
5185
5242
  Service.prototype.resolveAll = function resolveAll() {
5243
+ if (!this._needsRecursiveResolve) return this;
5244
+
5186
5245
  Namespace.prototype.resolve.call(this);
5187
5246
  var methods = this.methodsArray;
5188
5247
  for (var i = 0; i < methods.length; ++i)
@@ -5565,6 +5624,8 @@ Type.prototype.toJSON = function toJSON(toJSONOptions) {
5565
5624
  * @override
5566
5625
  */
5567
5626
  Type.prototype.resolveAll = function resolveAll() {
5627
+ if (!this._needsRecursiveResolve) return this;
5628
+
5568
5629
  Namespace.prototype.resolveAll.call(this);
5569
5630
  var oneofs = this.oneofsArray; i = 0;
5570
5631
  while (i < oneofs.length)