protobufjs 7.4.0 → 8.0.1-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.
- package/dist/light/protobuf.js +290 -68
- 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 +399 -122
- 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 +63 -12
- package/package.json +1 -1
- package/src/decoder.js +8 -10
- package/src/encoder.js +1 -1
- package/src/enum.js +43 -0
- package/src/field.js +82 -27
- package/src/index-light.js +1 -1
- package/src/namespace.js +2 -1
- package/src/object.js +93 -6
- package/src/oneof.js +19 -0
- package/src/parse.js +108 -53
- package/src/root.js +30 -14
- package/src/service.js +2 -1
- package/src/type.js +5 -4
- package/src/util.js +1 -0
package/dist/light/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v8.0.1-experimental (c) 2016, daniel wirtz
|
|
3
|
+
* compiled mon, 24 mar 2025 19:22:52 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -1430,16 +1430,14 @@ function missing(field) {
|
|
|
1430
1430
|
*/
|
|
1431
1431
|
function decoder(mtype) {
|
|
1432
1432
|
/* eslint-disable no-unexpected-multiline */
|
|
1433
|
-
var gen = util.codegen(["r", "l"], mtype.name + "$decode")
|
|
1433
|
+
var gen = util.codegen(["r", "l", "e"], mtype.name + "$decode")
|
|
1434
1434
|
("if(!(r instanceof Reader))")
|
|
1435
1435
|
("r=Reader.create(r)")
|
|
1436
1436
|
("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
|
|
1437
1437
|
("while(r.pos<c){")
|
|
1438
|
-
("var t=r.uint32()")
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
("break");
|
|
1442
|
-
gen
|
|
1438
|
+
("var t=r.uint32()")
|
|
1439
|
+
("if(t===e)")
|
|
1440
|
+
("break")
|
|
1443
1441
|
("switch(t>>>3){");
|
|
1444
1442
|
|
|
1445
1443
|
var i = 0;
|
|
@@ -1505,15 +1503,15 @@ function decoder(mtype) {
|
|
|
1505
1503
|
("}else");
|
|
1506
1504
|
|
|
1507
1505
|
// Non-packed
|
|
1508
|
-
if (types.basic[type] === undefined) gen(field.
|
|
1509
|
-
? "%s.push(types[%i].decode(r))"
|
|
1506
|
+
if (types.basic[type] === undefined) gen(field.delimited
|
|
1507
|
+
? "%s.push(types[%i].decode(r,undefined,((t&~7)|4)))"
|
|
1510
1508
|
: "%s.push(types[%i].decode(r,r.uint32()))", ref, i);
|
|
1511
1509
|
else gen
|
|
1512
1510
|
("%s.push(r.%s())", ref, type);
|
|
1513
1511
|
|
|
1514
1512
|
// Non-repeated
|
|
1515
|
-
} else if (types.basic[type] === undefined) gen(field.
|
|
1516
|
-
? "%s=types[%i].decode(r)"
|
|
1513
|
+
} else if (types.basic[type] === undefined) gen(field.delimited
|
|
1514
|
+
? "%s=types[%i].decode(r,undefined,((t&~7)|4))"
|
|
1517
1515
|
: "%s=types[%i].decode(r,r.uint32())", ref, i);
|
|
1518
1516
|
else gen
|
|
1519
1517
|
("%s=r.%s()", ref, type);
|
|
@@ -1560,7 +1558,7 @@ var Enum = require(14),
|
|
|
1560
1558
|
* @ignore
|
|
1561
1559
|
*/
|
|
1562
1560
|
function genTypePartial(gen, field, fieldIndex, ref) {
|
|
1563
|
-
return field.
|
|
1561
|
+
return field.delimited
|
|
1564
1562
|
? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
|
|
1565
1563
|
: gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
|
|
1566
1564
|
}
|
|
@@ -1703,6 +1701,18 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
1703
1701
|
*/
|
|
1704
1702
|
this.valuesOptions = valuesOptions;
|
|
1705
1703
|
|
|
1704
|
+
/**
|
|
1705
|
+
* Resolved values features, if any
|
|
1706
|
+
* @type {Object<string, Object<string, *>>|undefined}
|
|
1707
|
+
*/
|
|
1708
|
+
this._valuesFeatures = {};
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Unresolved values features, if any
|
|
1712
|
+
* @type {Object<string, Object<string, *>>|undefined}
|
|
1713
|
+
*/
|
|
1714
|
+
this._valuesProtoFeatures = {};
|
|
1715
|
+
|
|
1706
1716
|
/**
|
|
1707
1717
|
* Reserved ranges, if any.
|
|
1708
1718
|
* @type {Array.<number[]|string>}
|
|
@@ -1719,6 +1729,22 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
1719
1729
|
this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
|
|
1720
1730
|
}
|
|
1721
1731
|
|
|
1732
|
+
/**
|
|
1733
|
+
* Resolves value features
|
|
1734
|
+
* @returns {Enum} `this`
|
|
1735
|
+
*/
|
|
1736
|
+
Enum.prototype.resolve = function resolve() {
|
|
1737
|
+
ReflectionObject.prototype.resolve.call(this);
|
|
1738
|
+
|
|
1739
|
+
for (var key of Object.keys(this._valuesProtoFeatures)) {
|
|
1740
|
+
var parentFeaturesCopy = Object.assign({}, this._features);
|
|
1741
|
+
this._valuesFeatures[key] = Object.assign(parentFeaturesCopy, this._valuesProtoFeatures[key] || {});
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
return this;
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
|
|
1722
1748
|
/**
|
|
1723
1749
|
* Enum descriptor.
|
|
1724
1750
|
* @interface IEnum
|
|
@@ -1795,6 +1821,21 @@ Enum.prototype.add = function add(name, id, comment, options) {
|
|
|
1795
1821
|
if (this.valuesOptions === undefined)
|
|
1796
1822
|
this.valuesOptions = {};
|
|
1797
1823
|
this.valuesOptions[name] = options || null;
|
|
1824
|
+
|
|
1825
|
+
for (var key of Object.keys(this.valuesOptions)) {
|
|
1826
|
+
var features = Array.isArray(this.valuesOptions[key]) ? this.valuesOptions[key].find(x => {return Object.prototype.hasOwnProperty.call(x, "features");}) : this.valuesOptions[key] === "features";
|
|
1827
|
+
if (features) {
|
|
1828
|
+
this._valuesProtoFeatures[key] = features.features;
|
|
1829
|
+
} else {
|
|
1830
|
+
this._valuesProtoFeatures[key] = {};
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
for (var enumValue of Object.keys(this.values)) {
|
|
1836
|
+
if (!this._valuesProtoFeatures[enumValue]) {
|
|
1837
|
+
this._valuesProtoFeatures[enumValue] = {};
|
|
1838
|
+
}
|
|
1798
1839
|
}
|
|
1799
1840
|
|
|
1800
1841
|
this.comments[name] = comment || null;
|
|
@@ -1952,18 +1993,6 @@ function Field(name, id, type, rule, extend, options, comment) {
|
|
|
1952
1993
|
*/
|
|
1953
1994
|
this.extend = extend || undefined; // toJSON
|
|
1954
1995
|
|
|
1955
|
-
/**
|
|
1956
|
-
* Whether this field is required.
|
|
1957
|
-
* @type {boolean}
|
|
1958
|
-
*/
|
|
1959
|
-
this.required = rule === "required";
|
|
1960
|
-
|
|
1961
|
-
/**
|
|
1962
|
-
* Whether this field is optional.
|
|
1963
|
-
* @type {boolean}
|
|
1964
|
-
*/
|
|
1965
|
-
this.optional = !this.required;
|
|
1966
|
-
|
|
1967
1996
|
/**
|
|
1968
1997
|
* Whether this field is repeated.
|
|
1969
1998
|
* @type {boolean}
|
|
@@ -2030,13 +2059,6 @@ function Field(name, id, type, rule, extend, options, comment) {
|
|
|
2030
2059
|
*/
|
|
2031
2060
|
this.declaringField = null;
|
|
2032
2061
|
|
|
2033
|
-
/**
|
|
2034
|
-
* Internally remembers whether this field is packed.
|
|
2035
|
-
* @type {boolean|null}
|
|
2036
|
-
* @private
|
|
2037
|
-
*/
|
|
2038
|
-
this._packed = null;
|
|
2039
|
-
|
|
2040
2062
|
/**
|
|
2041
2063
|
* Comment for this field.
|
|
2042
2064
|
* @type {string|null}
|
|
@@ -2045,17 +2067,69 @@ function Field(name, id, type, rule, extend, options, comment) {
|
|
|
2045
2067
|
}
|
|
2046
2068
|
|
|
2047
2069
|
/**
|
|
2048
|
-
* Determines whether this field is
|
|
2070
|
+
* Determines whether this field is required.
|
|
2071
|
+
* @name Field#required
|
|
2072
|
+
* @type {boolean}
|
|
2073
|
+
* @readonly
|
|
2074
|
+
*/
|
|
2075
|
+
Object.defineProperty(Field.prototype, "required", {
|
|
2076
|
+
get: function() {
|
|
2077
|
+
return this._features.field_presence === "LEGACY_REQUIRED";
|
|
2078
|
+
}
|
|
2079
|
+
});
|
|
2080
|
+
|
|
2081
|
+
/**
|
|
2082
|
+
* Determines whether this field is not required.
|
|
2083
|
+
* @name Field#optional
|
|
2084
|
+
* @type {boolean}
|
|
2085
|
+
* @readonly
|
|
2086
|
+
*/
|
|
2087
|
+
Object.defineProperty(Field.prototype, "optional", {
|
|
2088
|
+
get: function() {
|
|
2089
|
+
return !this.required;
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
|
|
2093
|
+
/**
|
|
2094
|
+
* Determines whether this field uses tag-delimited encoding. In proto2 this
|
|
2095
|
+
* corresponded to group syntax.
|
|
2096
|
+
* @name Field#delimited
|
|
2097
|
+
* @type {boolean}
|
|
2098
|
+
* @readonly
|
|
2099
|
+
*/
|
|
2100
|
+
Object.defineProperty(Field.prototype, "delimited", {
|
|
2101
|
+
get: function() {
|
|
2102
|
+
return this.resolvedType instanceof Type &&
|
|
2103
|
+
this._features.message_encoding === "DELIMITED";
|
|
2104
|
+
}
|
|
2105
|
+
});
|
|
2106
|
+
|
|
2107
|
+
/**
|
|
2108
|
+
* Determines whether this field is packed. Only relevant when repeated.
|
|
2049
2109
|
* @name Field#packed
|
|
2050
2110
|
* @type {boolean}
|
|
2051
2111
|
* @readonly
|
|
2052
2112
|
*/
|
|
2053
2113
|
Object.defineProperty(Field.prototype, "packed", {
|
|
2054
2114
|
get: function() {
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2115
|
+
return this._features.repeated_field_encoding === "PACKED";
|
|
2116
|
+
}
|
|
2117
|
+
});
|
|
2118
|
+
|
|
2119
|
+
/**
|
|
2120
|
+
* Determines whether this field tracks presence.
|
|
2121
|
+
* @name Field#hasPresence
|
|
2122
|
+
* @type {boolean}
|
|
2123
|
+
* @readonly
|
|
2124
|
+
*/
|
|
2125
|
+
Object.defineProperty(Field.prototype, "hasPresence", {
|
|
2126
|
+
get: function() {
|
|
2127
|
+
if (this.repeated || this.map) {
|
|
2128
|
+
return false;
|
|
2129
|
+
}
|
|
2130
|
+
return this.partOf || // oneofs
|
|
2131
|
+
this.declaringField || this.extensionField || // extensions
|
|
2132
|
+
this._features.field_presence !== "IMPLICIT";
|
|
2059
2133
|
}
|
|
2060
2134
|
});
|
|
2061
2135
|
|
|
@@ -2063,8 +2137,6 @@ Object.defineProperty(Field.prototype, "packed", {
|
|
|
2063
2137
|
* @override
|
|
2064
2138
|
*/
|
|
2065
2139
|
Field.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
2066
|
-
if (name === "packed") // clear cached before setting
|
|
2067
|
-
this._packed = null;
|
|
2068
2140
|
return ReflectionObject.prototype.setOption.call(this, name, value, ifNotSet);
|
|
2069
2141
|
};
|
|
2070
2142
|
|
|
@@ -2131,7 +2203,7 @@ Field.prototype.resolve = function resolve() {
|
|
|
2131
2203
|
|
|
2132
2204
|
// remove unnecessary options
|
|
2133
2205
|
if (this.options) {
|
|
2134
|
-
if (this.options.packed
|
|
2206
|
+
if (this.options.packed !== undefined && this.resolvedType && !(this.resolvedType instanceof Enum))
|
|
2135
2207
|
delete this.options.packed;
|
|
2136
2208
|
if (!Object.keys(this.options).length)
|
|
2137
2209
|
this.options = undefined;
|
|
@@ -2169,6 +2241,30 @@ Field.prototype.resolve = function resolve() {
|
|
|
2169
2241
|
return ReflectionObject.prototype.resolve.call(this);
|
|
2170
2242
|
};
|
|
2171
2243
|
|
|
2244
|
+
/**
|
|
2245
|
+
* Infers field features from legacy syntax that may have been specified differently.
|
|
2246
|
+
* in older editions.
|
|
2247
|
+
* @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
|
|
2248
|
+
* @returns {object} The feature values to override
|
|
2249
|
+
*/
|
|
2250
|
+
Field.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(edition) {
|
|
2251
|
+
if (edition) return {};
|
|
2252
|
+
|
|
2253
|
+
var features = {};
|
|
2254
|
+
if (this.rule === "required") {
|
|
2255
|
+
features.field_presence = "LEGACY_REQUIRED";
|
|
2256
|
+
}
|
|
2257
|
+
if (this.resolvedType instanceof Type && this.resolvedType.group) {
|
|
2258
|
+
features.message_encoding = "DELIMITED";
|
|
2259
|
+
}
|
|
2260
|
+
if (this.getOption("packed") === true) {
|
|
2261
|
+
features.repeated_field_encoding = "PACKED";
|
|
2262
|
+
} else if (this.getOption("packed") === false) {
|
|
2263
|
+
features.repeated_field_encoding = "EXPANDED";
|
|
2264
|
+
}
|
|
2265
|
+
return features;
|
|
2266
|
+
};
|
|
2267
|
+
|
|
2172
2268
|
/**
|
|
2173
2269
|
* Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
|
|
2174
2270
|
* @typedef FieldDecorator
|
|
@@ -2324,7 +2420,7 @@ protobuf.types = require(32);
|
|
|
2324
2420
|
protobuf.util = require(33);
|
|
2325
2421
|
|
|
2326
2422
|
// Set up possibly cyclic reflection dependencies
|
|
2327
|
-
protobuf.ReflectionObject._configure(protobuf.Root);
|
|
2423
|
+
protobuf.ReflectionObject._configure(protobuf.Root, protobuf.Namespace);
|
|
2328
2424
|
protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
|
|
2329
2425
|
protobuf.Root._configure(protobuf.Type);
|
|
2330
2426
|
protobuf.Field._configure(protobuf.Type);
|
|
@@ -3102,12 +3198,13 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
3102
3198
|
*/
|
|
3103
3199
|
Namespace.prototype.resolveAll = function resolveAll() {
|
|
3104
3200
|
var nested = this.nestedArray, i = 0;
|
|
3201
|
+
this.resolve();
|
|
3105
3202
|
while (i < nested.length)
|
|
3106
3203
|
if (nested[i] instanceof Namespace)
|
|
3107
3204
|
nested[i++].resolveAll();
|
|
3108
3205
|
else
|
|
3109
3206
|
nested[i++].resolve();
|
|
3110
|
-
return this
|
|
3207
|
+
return this;
|
|
3111
3208
|
};
|
|
3112
3209
|
|
|
3113
3210
|
/**
|
|
@@ -3238,9 +3335,16 @@ module.exports = ReflectionObject;
|
|
|
3238
3335
|
|
|
3239
3336
|
ReflectionObject.className = "ReflectionObject";
|
|
3240
3337
|
|
|
3338
|
+
const OneOf = require(23);
|
|
3241
3339
|
var util = require(33);
|
|
3242
3340
|
|
|
3243
|
-
var Root; // cyclic
|
|
3341
|
+
var Root, Namespace; // cyclic
|
|
3342
|
+
|
|
3343
|
+
/* eslint-disable no-warning-comments */
|
|
3344
|
+
// TODO: Replace with embedded proto.
|
|
3345
|
+
var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
|
|
3346
|
+
var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE"};
|
|
3347
|
+
var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
|
|
3244
3348
|
|
|
3245
3349
|
/**
|
|
3246
3350
|
* Constructs a new reflection object instance.
|
|
@@ -3276,6 +3380,16 @@ function ReflectionObject(name, options) {
|
|
|
3276
3380
|
*/
|
|
3277
3381
|
this.name = name;
|
|
3278
3382
|
|
|
3383
|
+
/**
|
|
3384
|
+
* Resolved Features.
|
|
3385
|
+
*/
|
|
3386
|
+
this._features = {};
|
|
3387
|
+
|
|
3388
|
+
/**
|
|
3389
|
+
* Unresolved Features.
|
|
3390
|
+
*/
|
|
3391
|
+
this._protoFeatures = null;
|
|
3392
|
+
|
|
3279
3393
|
/**
|
|
3280
3394
|
* Parent namespace.
|
|
3281
3395
|
* @type {Namespace|null}
|
|
@@ -3381,11 +3495,69 @@ ReflectionObject.prototype.onRemove = function onRemove(parent) {
|
|
|
3381
3495
|
ReflectionObject.prototype.resolve = function resolve() {
|
|
3382
3496
|
if (this.resolved)
|
|
3383
3497
|
return this;
|
|
3384
|
-
|
|
3385
|
-
|
|
3498
|
+
var edition = this.getOption("edition");
|
|
3499
|
+
if ((this instanceof Namespace && edition) || (this.parent && this.parent.resolved)) {
|
|
3500
|
+
this._resolveFeatures();
|
|
3501
|
+
this.resolved = true;
|
|
3502
|
+
}
|
|
3386
3503
|
return this;
|
|
3387
3504
|
};
|
|
3388
3505
|
|
|
3506
|
+
/**
|
|
3507
|
+
* Resolves child features from parent features
|
|
3508
|
+
* @returns {undefined}
|
|
3509
|
+
*/
|
|
3510
|
+
ReflectionObject.prototype._resolveFeatures = function _resolveFeatures() {
|
|
3511
|
+
var defaults = {};
|
|
3512
|
+
|
|
3513
|
+
var protoFeatures = Object.assign(Object.assign({}, this._protoFeatures), this._inferLegacyProtoFeatures(edition));
|
|
3514
|
+
|
|
3515
|
+
var edition = this.getOption("edition");
|
|
3516
|
+
if (this instanceof Namespace && edition) {
|
|
3517
|
+
// For a namespace marked with a specific edition, reset defaults.
|
|
3518
|
+
if (edition === "proto2") {
|
|
3519
|
+
defaults = Object.assign({}, proto2Defaults);
|
|
3520
|
+
} else if (edition === "proto3") {
|
|
3521
|
+
defaults = Object.assign({}, proto3Defaults);
|
|
3522
|
+
} else if (edition === "2023") {
|
|
3523
|
+
defaults = Object.assign({}, editions2023Defaults);
|
|
3524
|
+
} else {
|
|
3525
|
+
throw new Error("Unknown edition: " + edition);
|
|
3526
|
+
}
|
|
3527
|
+
this._features = Object.assign(defaults, protoFeatures || {});
|
|
3528
|
+
return;
|
|
3529
|
+
}
|
|
3530
|
+
|
|
3531
|
+
// fields in Oneofs aren't actually children of them, so we have to
|
|
3532
|
+
// special-case it
|
|
3533
|
+
if (this.partOf instanceof OneOf) {
|
|
3534
|
+
var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
|
|
3535
|
+
this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
|
|
3536
|
+
} else if (this.declaringField) {
|
|
3537
|
+
// Skip feature resolution of sister fields.
|
|
3538
|
+
} else if (this.parent) {
|
|
3539
|
+
var parentFeaturesCopy = Object.assign({}, this.parent._features);
|
|
3540
|
+
this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
|
|
3541
|
+
} else {
|
|
3542
|
+
this._features = Object.assign({}, protoFeatures);
|
|
3543
|
+
}
|
|
3544
|
+
if (this.extensionField) {
|
|
3545
|
+
// Sister fields should have the same features as their extensions.
|
|
3546
|
+
this.extensionField._features = this._features;
|
|
3547
|
+
}
|
|
3548
|
+
};
|
|
3549
|
+
|
|
3550
|
+
/**
|
|
3551
|
+
* Infers features from legacy syntax that may have been specified differently.
|
|
3552
|
+
* in older editions.
|
|
3553
|
+
* @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
|
|
3554
|
+
* @returns {object} The feature values to override
|
|
3555
|
+
* @abstract
|
|
3556
|
+
*/
|
|
3557
|
+
ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
|
|
3558
|
+
return {};
|
|
3559
|
+
};
|
|
3560
|
+
|
|
3389
3561
|
/**
|
|
3390
3562
|
* Gets an option value.
|
|
3391
3563
|
* @param {string} name Option name
|
|
@@ -3405,8 +3577,10 @@ ReflectionObject.prototype.getOption = function getOption(name) {
|
|
|
3405
3577
|
* @returns {ReflectionObject} `this`
|
|
3406
3578
|
*/
|
|
3407
3579
|
ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
3408
|
-
if (!ifNotSet || !this.options || this.options[name] === undefined)
|
|
3580
|
+
if (!ifNotSet || !this.options || this.options[name] === undefined) {
|
|
3581
|
+
if (this.getOption(name) !== value) this.resolved = false;
|
|
3409
3582
|
(this.options || (this.options = {}))[name] = value;
|
|
3583
|
+
}
|
|
3410
3584
|
return this;
|
|
3411
3585
|
};
|
|
3412
3586
|
|
|
@@ -3421,6 +3595,7 @@ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, valu
|
|
|
3421
3595
|
if (!this.parsedOptions) {
|
|
3422
3596
|
this.parsedOptions = [];
|
|
3423
3597
|
}
|
|
3598
|
+
var isFeature = /^features$/.test(name);
|
|
3424
3599
|
var parsedOptions = this.parsedOptions;
|
|
3425
3600
|
if (propName) {
|
|
3426
3601
|
// If setting a sub property of an option then try to merge it
|
|
@@ -3430,10 +3605,11 @@ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, valu
|
|
|
3430
3605
|
});
|
|
3431
3606
|
if (opt) {
|
|
3432
3607
|
// If we found an existing option - just merge the property value
|
|
3608
|
+
// (If it's a feature, will just write over)
|
|
3433
3609
|
var newValue = opt[name];
|
|
3434
3610
|
util.setProperty(newValue, propName, value);
|
|
3435
3611
|
} else {
|
|
3436
|
-
// otherwise, create a new option, set
|
|
3612
|
+
// otherwise, create a new option, set its property and add it to the list
|
|
3437
3613
|
opt = {};
|
|
3438
3614
|
opt[name] = util.setProperty({}, propName, value);
|
|
3439
3615
|
parsedOptions.push(opt);
|
|
@@ -3444,6 +3620,13 @@ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, valu
|
|
|
3444
3620
|
newOpt[name] = value;
|
|
3445
3621
|
parsedOptions.push(newOpt);
|
|
3446
3622
|
}
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
if (isFeature) {
|
|
3626
|
+
var features = parsedOptions.find(x => {return Object.prototype.hasOwnProperty.call(x, "features");});
|
|
3627
|
+
this._protoFeatures = features.features || {};
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3447
3630
|
return this;
|
|
3448
3631
|
};
|
|
3449
3632
|
|
|
@@ -3473,11 +3656,12 @@ ReflectionObject.prototype.toString = function toString() {
|
|
|
3473
3656
|
};
|
|
3474
3657
|
|
|
3475
3658
|
// Sets up cyclic dependencies (called in index-light)
|
|
3476
|
-
ReflectionObject._configure = function(Root_) {
|
|
3659
|
+
ReflectionObject._configure = function(Root_, Namespace_) {
|
|
3477
3660
|
Root = Root_;
|
|
3661
|
+
Namespace = Namespace_;
|
|
3478
3662
|
};
|
|
3479
3663
|
|
|
3480
|
-
},{"33":33}],23:[function(require,module,exports){
|
|
3664
|
+
},{"23":23,"33":33}],23:[function(require,module,exports){
|
|
3481
3665
|
"use strict";
|
|
3482
3666
|
module.exports = OneOf;
|
|
3483
3667
|
|
|
@@ -3651,6 +3835,25 @@ OneOf.prototype.onRemove = function onRemove(parent) {
|
|
|
3651
3835
|
ReflectionObject.prototype.onRemove.call(this, parent);
|
|
3652
3836
|
};
|
|
3653
3837
|
|
|
3838
|
+
/**
|
|
3839
|
+
* Determines whether this field corresponds to a synthetic oneof created for
|
|
3840
|
+
* a proto3 optional field. No behavioral logic should depend on this, but it
|
|
3841
|
+
* can be relevant for reflection.
|
|
3842
|
+
* @name OneOf#isProto3Optional
|
|
3843
|
+
* @type {boolean}
|
|
3844
|
+
* @readonly
|
|
3845
|
+
*/
|
|
3846
|
+
Object.defineProperty(OneOf.prototype, "isProto3Optional", {
|
|
3847
|
+
get: function() {
|
|
3848
|
+
if (this.fieldsArray == null || this.fieldsArray.length !== 1) {
|
|
3849
|
+
return false;
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3852
|
+
var field = this.fieldsArray[0];
|
|
3853
|
+
return field.options != null && field.options["proto3_optional"] === true;
|
|
3854
|
+
}
|
|
3855
|
+
});
|
|
3856
|
+
|
|
3654
3857
|
/**
|
|
3655
3858
|
* Decorator function as returned by {@link OneOf.d} (TypeScript).
|
|
3656
3859
|
* @typedef OneOfDecorator
|
|
@@ -4191,11 +4394,14 @@ function Root(options) {
|
|
|
4191
4394
|
* @type {string[]}
|
|
4192
4395
|
*/
|
|
4193
4396
|
this.files = [];
|
|
4397
|
+
|
|
4398
|
+
// Default to proto2 if not specified.
|
|
4399
|
+
this.setOption("edition", "proto2", true);
|
|
4194
4400
|
}
|
|
4195
4401
|
|
|
4196
4402
|
/**
|
|
4197
4403
|
* Loads a namespace descriptor into a root namespace.
|
|
4198
|
-
* @param {INamespace} json
|
|
4404
|
+
* @param {INamespace} json Namespace descriptor
|
|
4199
4405
|
* @param {Root} [root] Root namespace, defaults to create a new one if omitted
|
|
4200
4406
|
* @returns {Root} Root namespace
|
|
4201
4407
|
*/
|
|
@@ -4244,20 +4450,26 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4244
4450
|
options = undefined;
|
|
4245
4451
|
}
|
|
4246
4452
|
var self = this;
|
|
4247
|
-
if (!callback)
|
|
4453
|
+
if (!callback) {
|
|
4248
4454
|
return util.asPromise(load, self, filename, options);
|
|
4455
|
+
}
|
|
4249
4456
|
|
|
4250
4457
|
var sync = callback === SYNC; // undocumented
|
|
4251
4458
|
|
|
4252
4459
|
// Finishes loading by calling the callback (exactly once)
|
|
4253
4460
|
function finish(err, root) {
|
|
4254
4461
|
/* istanbul ignore if */
|
|
4255
|
-
if (!callback)
|
|
4462
|
+
if (!callback) {
|
|
4256
4463
|
return;
|
|
4257
|
-
|
|
4464
|
+
}
|
|
4465
|
+
if (sync) {
|
|
4258
4466
|
throw err;
|
|
4467
|
+
}
|
|
4259
4468
|
var cb = callback;
|
|
4260
4469
|
callback = null;
|
|
4470
|
+
if (root) {
|
|
4471
|
+
root.resolveAll();
|
|
4472
|
+
}
|
|
4261
4473
|
cb(err, root);
|
|
4262
4474
|
}
|
|
4263
4475
|
|
|
@@ -4295,8 +4507,9 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4295
4507
|
} catch (err) {
|
|
4296
4508
|
finish(err);
|
|
4297
4509
|
}
|
|
4298
|
-
if (!sync && !queued)
|
|
4510
|
+
if (!sync && !queued) {
|
|
4299
4511
|
finish(null, self); // only once anyway
|
|
4512
|
+
}
|
|
4300
4513
|
}
|
|
4301
4514
|
|
|
4302
4515
|
// Fetches a single file
|
|
@@ -4304,15 +4517,16 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4304
4517
|
filename = getBundledFileName(filename) || filename;
|
|
4305
4518
|
|
|
4306
4519
|
// Skip if already loaded / attempted
|
|
4307
|
-
if (self.files.indexOf(filename) > -1)
|
|
4520
|
+
if (self.files.indexOf(filename) > -1) {
|
|
4308
4521
|
return;
|
|
4522
|
+
}
|
|
4309
4523
|
self.files.push(filename);
|
|
4310
4524
|
|
|
4311
4525
|
// Shortcut bundled definitions
|
|
4312
4526
|
if (filename in common) {
|
|
4313
|
-
if (sync)
|
|
4527
|
+
if (sync) {
|
|
4314
4528
|
process(filename, common[filename]);
|
|
4315
|
-
else {
|
|
4529
|
+
} else {
|
|
4316
4530
|
++queued;
|
|
4317
4531
|
setTimeout(function() {
|
|
4318
4532
|
--queued;
|
|
@@ -4338,8 +4552,9 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4338
4552
|
self.fetch(filename, function(err, source) {
|
|
4339
4553
|
--queued;
|
|
4340
4554
|
/* istanbul ignore if */
|
|
4341
|
-
if (!callback)
|
|
4555
|
+
if (!callback) {
|
|
4342
4556
|
return; // terminated meanwhile
|
|
4557
|
+
}
|
|
4343
4558
|
if (err) {
|
|
4344
4559
|
/* istanbul ignore else */
|
|
4345
4560
|
if (!weak)
|
|
@@ -4356,17 +4571,21 @@ Root.prototype.load = function load(filename, options, callback) {
|
|
|
4356
4571
|
|
|
4357
4572
|
// Assembling the root namespace doesn't require working type
|
|
4358
4573
|
// references anymore, so we can load everything in parallel
|
|
4359
|
-
if (util.isString(filename))
|
|
4574
|
+
if (util.isString(filename)) {
|
|
4360
4575
|
filename = [ filename ];
|
|
4576
|
+
}
|
|
4361
4577
|
for (var i = 0, resolved; i < filename.length; ++i)
|
|
4362
4578
|
if (resolved = self.resolvePath("", filename[i]))
|
|
4363
4579
|
fetch(resolved);
|
|
4364
|
-
|
|
4365
|
-
if (sync)
|
|
4580
|
+
self.resolveAll();
|
|
4581
|
+
if (sync) {
|
|
4366
4582
|
return self;
|
|
4367
|
-
|
|
4583
|
+
}
|
|
4584
|
+
if (!queued) {
|
|
4368
4585
|
finish(null, self);
|
|
4369
|
-
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
return self;
|
|
4370
4589
|
};
|
|
4371
4590
|
// function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
|
|
4372
4591
|
|
|
@@ -4834,10 +5053,11 @@ Service.prototype.get = function get(name) {
|
|
|
4834
5053
|
* @override
|
|
4835
5054
|
*/
|
|
4836
5055
|
Service.prototype.resolveAll = function resolveAll() {
|
|
5056
|
+
Namespace.prototype.resolve.call(this);
|
|
4837
5057
|
var methods = this.methodsArray;
|
|
4838
5058
|
for (var i = 0; i < methods.length; ++i)
|
|
4839
5059
|
methods[i].resolve();
|
|
4840
|
-
return
|
|
5060
|
+
return this;
|
|
4841
5061
|
};
|
|
4842
5062
|
|
|
4843
5063
|
/**
|
|
@@ -5196,13 +5416,14 @@ Type.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
5196
5416
|
* @override
|
|
5197
5417
|
*/
|
|
5198
5418
|
Type.prototype.resolveAll = function resolveAll() {
|
|
5199
|
-
|
|
5200
|
-
while (i < fields.length)
|
|
5201
|
-
fields[i++].resolve();
|
|
5419
|
+
Namespace.prototype.resolveAll.call(this);
|
|
5202
5420
|
var oneofs = this.oneofsArray; i = 0;
|
|
5203
5421
|
while (i < oneofs.length)
|
|
5204
5422
|
oneofs[i++].resolve();
|
|
5205
|
-
|
|
5423
|
+
var fields = this.fieldsArray, i = 0;
|
|
5424
|
+
while (i < fields.length)
|
|
5425
|
+
fields[i++].resolve();
|
|
5426
|
+
return this;
|
|
5206
5427
|
};
|
|
5207
5428
|
|
|
5208
5429
|
/**
|
|
@@ -5857,6 +6078,7 @@ util.decorateEnum = function decorateEnum(object) {
|
|
|
5857
6078
|
* @param {Object.<string,*>} dst Destination object
|
|
5858
6079
|
* @param {string} path dot '.' delimited path of the property to set
|
|
5859
6080
|
* @param {Object} value the value to set
|
|
6081
|
+
* @param {boolean} overWrite whether or not to concatenate the values into an array or overwrite; defaults to false.
|
|
5860
6082
|
* @returns {Object.<string,*>} Destination object
|
|
5861
6083
|
*/
|
|
5862
6084
|
util.setProperty = function setProperty(dst, path, value) {
|