protobufjs 7.5.0 → 7.5.1
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.
- package/dist/light/protobuf.js +103 -26
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +2 -2
- package/dist/minimal/protobuf.min.js +2 -2
- package/dist/protobuf.js +107 -26
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +6 -0
- package/package.json +4 -2
- package/src/field.js +9 -3
- package/src/namespace.js +68 -12
- package/src/object.js +14 -4
- package/src/parse.js +4 -0
- package/src/root.js +6 -5
- package/src/service.js +2 -0
- package/src/type.js +2 -0
package/dist/light/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js v7.5.
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v7.5.1 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled thu, 08 may 2025 17:34:56 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -2240,12 +2240,18 @@ Field.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(e
|
|
|
2240
2240
|
}
|
|
2241
2241
|
|
|
2242
2242
|
var features = {};
|
|
2243
|
-
|
|
2243
|
+
|
|
2244
2244
|
if (this.rule === "required") {
|
|
2245
2245
|
features.field_presence = "LEGACY_REQUIRED";
|
|
2246
2246
|
}
|
|
2247
|
-
if (this.
|
|
2248
|
-
|
|
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
|
+
}
|
|
2249
2255
|
}
|
|
2250
2256
|
if (this.getOption("packed") === true) {
|
|
2251
2257
|
features.repeated_field_encoding = "PACKED";
|
|
@@ -3001,10 +3007,33 @@ function Namespace(name, options) {
|
|
|
3001
3007
|
* @private
|
|
3002
3008
|
*/
|
|
3003
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;
|
|
3004
3026
|
}
|
|
3005
3027
|
|
|
3006
3028
|
function clearCache(namespace) {
|
|
3007
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
|
+
}
|
|
3008
3037
|
return namespace;
|
|
3009
3038
|
}
|
|
3010
3039
|
|
|
@@ -3142,6 +3171,14 @@ Namespace.prototype.add = function add(object) {
|
|
|
3142
3171
|
}
|
|
3143
3172
|
}
|
|
3144
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
|
+
|
|
3145
3182
|
object.onAdd(this);
|
|
3146
3183
|
return clearCache(this);
|
|
3147
3184
|
};
|
|
@@ -3217,6 +3254,9 @@ Namespace.prototype.resolveAll = function resolveAll() {
|
|
|
3217
3254
|
* @override
|
|
3218
3255
|
*/
|
|
3219
3256
|
Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
|
|
3257
|
+
if (!this._needsRecursiveFeatureResolution) return this;
|
|
3258
|
+
this._needsRecursiveFeatureResolution = false;
|
|
3259
|
+
|
|
3220
3260
|
edition = this._edition || edition;
|
|
3221
3261
|
|
|
3222
3262
|
ReflectionObject.prototype._resolveFeaturesRecursive.call(this, edition);
|
|
@@ -3234,7 +3274,6 @@ Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursi
|
|
|
3234
3274
|
* @returns {ReflectionObject|null} Looked up object or `null` if none could be found
|
|
3235
3275
|
*/
|
|
3236
3276
|
Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {
|
|
3237
|
-
|
|
3238
3277
|
/* istanbul ignore next */
|
|
3239
3278
|
if (typeof filterTypes === "boolean") {
|
|
3240
3279
|
parentAlreadyChecked = filterTypes;
|
|
@@ -3253,25 +3292,48 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
|
|
|
3253
3292
|
if (path[0] === "")
|
|
3254
3293
|
return this.root.lookup(path.slice(1), filterTypes);
|
|
3255
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
|
+
|
|
3256
3318
|
// Test if the first part matches any nested object, and if so, traverse if path contains more
|
|
3257
3319
|
var found = this.get(path[0]);
|
|
3320
|
+
var exact = null;
|
|
3258
3321
|
if (found) {
|
|
3259
3322
|
if (path.length === 1) {
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
return found;
|
|
3323
|
+
exact = found;
|
|
3324
|
+
} else if (found instanceof Namespace && (found = found._lookupImpl(path.slice(1))))
|
|
3325
|
+
exact = found;
|
|
3264
3326
|
|
|
3265
3327
|
// Otherwise try each nested namespace
|
|
3266
|
-
} else
|
|
3328
|
+
} else {
|
|
3267
3329
|
for (var i = 0; i < this.nestedArray.length; ++i)
|
|
3268
|
-
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].
|
|
3269
|
-
|
|
3330
|
+
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path)))
|
|
3331
|
+
exact = found;
|
|
3332
|
+
}
|
|
3270
3333
|
|
|
3271
|
-
//
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
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;
|
|
3275
3337
|
};
|
|
3276
3338
|
|
|
3277
3339
|
/**
|
|
@@ -3418,6 +3480,12 @@ function ReflectionObject(name, options) {
|
|
|
3418
3480
|
*/
|
|
3419
3481
|
this._features = {};
|
|
3420
3482
|
|
|
3483
|
+
/**
|
|
3484
|
+
* Whether or not features have been resolved.
|
|
3485
|
+
* @type {boolean}
|
|
3486
|
+
*/
|
|
3487
|
+
this._featuresResolved = false;
|
|
3488
|
+
|
|
3421
3489
|
/**
|
|
3422
3490
|
* Parent namespace.
|
|
3423
3491
|
* @type {Namespace|null}
|
|
@@ -3523,10 +3591,8 @@ ReflectionObject.prototype.onRemove = function onRemove(parent) {
|
|
|
3523
3591
|
ReflectionObject.prototype.resolve = function resolve() {
|
|
3524
3592
|
if (this.resolved)
|
|
3525
3593
|
return this;
|
|
3526
|
-
if (this instanceof Root)
|
|
3527
|
-
this.
|
|
3528
|
-
this.resolved = true;
|
|
3529
|
-
}
|
|
3594
|
+
if (this.root instanceof Root)
|
|
3595
|
+
this.resolved = true; // only if part of a root
|
|
3530
3596
|
return this;
|
|
3531
3597
|
};
|
|
3532
3598
|
|
|
@@ -3545,6 +3611,10 @@ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeatures
|
|
|
3545
3611
|
* @returns {undefined}
|
|
3546
3612
|
*/
|
|
3547
3613
|
ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
3614
|
+
if (this._featuresResolved) {
|
|
3615
|
+
return;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3548
3618
|
var defaults = {};
|
|
3549
3619
|
|
|
3550
3620
|
/* istanbul ignore if */
|
|
@@ -3568,6 +3638,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
|
|
|
3568
3638
|
throw new Error("Unknown edition: " + edition);
|
|
3569
3639
|
}
|
|
3570
3640
|
this._features = Object.assign(defaults, protoFeatures || {});
|
|
3641
|
+
this._featuresResolved = true;
|
|
3571
3642
|
return;
|
|
3572
3643
|
}
|
|
3573
3644
|
|
|
@@ -3589,6 +3660,7 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
|
|
|
3589
3660
|
// Sister fields should have the same features as their extensions.
|
|
3590
3661
|
this.extensionField._features = this._features;
|
|
3591
3662
|
}
|
|
3663
|
+
this._featuresResolved = true;
|
|
3592
3664
|
};
|
|
3593
3665
|
|
|
3594
3666
|
/**
|
|
@@ -4463,7 +4535,7 @@ Root.fromJSON = function fromJSON(json, root) {
|
|
|
4463
4535
|
root = new Root();
|
|
4464
4536
|
if (json.options)
|
|
4465
4537
|
root.setOptions(json.options);
|
|
4466
|
-
return root.addJSON(json.nested).
|
|
4538
|
+
return root.addJSON(json.nested)._resolveFeaturesRecursive();
|
|
4467
4539
|
};
|
|
4468
4540
|
|
|
4469
4541
|
/**
|
|
@@ -4511,6 +4583,9 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4511
4583
|
|
|
4512
4584
|
// Finishes loading by calling the callback (exactly once)
|
|
4513
4585
|
function finish(err, root) {
|
|
4586
|
+
if (root) {
|
|
4587
|
+
root._resolveFeaturesRecursive();
|
|
4588
|
+
}
|
|
4514
4589
|
/* istanbul ignore if */
|
|
4515
4590
|
if (!callback) {
|
|
4516
4591
|
return;
|
|
@@ -4520,9 +4595,6 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4520
4595
|
}
|
|
4521
4596
|
var cb = callback;
|
|
4522
4597
|
callback = null;
|
|
4523
|
-
if (root) {
|
|
4524
|
-
root.resolveAll();
|
|
4525
|
-
}
|
|
4526
4598
|
cb(err, root);
|
|
4527
4599
|
}
|
|
4528
4600
|
|
|
@@ -4630,8 +4702,8 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4630
4702
|
for (var i = 0, resolved; i < filename.length; ++i)
|
|
4631
4703
|
if (resolved = self.resolvePath("", filename[i]))
|
|
4632
4704
|
fetch(resolved);
|
|
4633
|
-
self.resolveAll();
|
|
4634
4705
|
if (sync) {
|
|
4706
|
+
self._resolveFeaturesRecursive();
|
|
4635
4707
|
return self;
|
|
4636
4708
|
}
|
|
4637
4709
|
if (!queued) {
|
|
@@ -4684,6 +4756,7 @@ Root.prototype.resolveAll = function resolveAll() {
|
|
|
4684
4756
|
throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
|
|
4685
4757
|
return "'extend " + field.extend + "' in " + field.parent.fullName;
|
|
4686
4758
|
}).join(", "));
|
|
4759
|
+
this._resolveFeaturesRecursive(this._edition);
|
|
4687
4760
|
return Namespace.prototype.resolveAll.call(this);
|
|
4688
4761
|
};
|
|
4689
4762
|
|
|
@@ -5121,6 +5194,8 @@ Service.prototype.resolveAll = function resolveAll() {
|
|
|
5121
5194
|
* @override
|
|
5122
5195
|
*/
|
|
5123
5196
|
Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
|
|
5197
|
+
if (!this._needsRecursiveFeatureResolution) return this;
|
|
5198
|
+
|
|
5124
5199
|
edition = this._edition || edition;
|
|
5125
5200
|
|
|
5126
5201
|
Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
|
|
@@ -5504,6 +5579,8 @@ Type.prototype.resolveAll = function resolveAll() {
|
|
|
5504
5579
|
* @override
|
|
5505
5580
|
*/
|
|
5506
5581
|
Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
|
|
5582
|
+
if (!this._needsRecursiveFeatureResolution) return this;
|
|
5583
|
+
|
|
5507
5584
|
edition = this._edition || edition;
|
|
5508
5585
|
|
|
5509
5586
|
Namespace.prototype._resolveFeaturesRecursive.call(this, edition);
|