protobufjs 7.0.0 → 7.1.0

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/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v6.10.2 (c) 2016, daniel wirtz
3
- * compiled fri, 08 jul 2022 16:17:13 utc
2
+ * protobuf.js v7.1.0 (c) 2016, daniel wirtz
3
+ * compiled fri, 26 aug 2022 21:49:00 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -1535,8 +1535,14 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1535
1535
  if (field.resolvedType instanceof Enum) { gen
1536
1536
  ("switch(d%s){", prop);
1537
1537
  for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
1538
- if (field.repeated && values[keys[i]] === field.typeDefault) gen
1539
- ("default:");
1538
+ // enum unknown values passthrough
1539
+ if (values[keys[i]] === field.typeDefault) { gen
1540
+ ("default:")
1541
+ ("if(typeof(d%s)===\"number\"){m%s=d%s;break}", prop, prop, prop);
1542
+ if (!field.repeated) gen // fallback to default value only for
1543
+ // arrays, to avoid leaving holes.
1544
+ ("break"); // for non-repeated fields, just ignore
1545
+ }
1540
1546
  gen
1541
1547
  ("case%j:", keys[i])
1542
1548
  ("case %i:", values[keys[i]])
@@ -1668,7 +1674,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
1668
1674
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1669
1675
  if (field.resolvedType) {
1670
1676
  if (field.resolvedType instanceof Enum) gen
1671
- ("d%s=o.enums===String?types[%i].values[m%s]:m%s", prop, fieldIndex, prop, prop);
1677
+ ("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
1672
1678
  else gen
1673
1679
  ("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
1674
1680
  } else {
@@ -2058,8 +2064,9 @@ var Namespace = require(23),
2058
2064
  * @param {Object.<string,*>} [options] Declared options
2059
2065
  * @param {string} [comment] The comment for this enum
2060
2066
  * @param {Object.<string,string>} [comments] The value comments for this enum
2067
+ * @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
2061
2068
  */
2062
- function Enum(name, values, options, comment, comments) {
2069
+ function Enum(name, values, options, comment, comments, valuesOptions) {
2063
2070
  ReflectionObject.call(this, name, options);
2064
2071
 
2065
2072
  if (values && typeof values !== "object")
@@ -2089,6 +2096,12 @@ function Enum(name, values, options, comment, comments) {
2089
2096
  */
2090
2097
  this.comments = comments || {};
2091
2098
 
2099
+ /**
2100
+ * Values options, if any
2101
+ * @type {Object<string, Object<string, *>>|undefined}
2102
+ */
2103
+ this.valuesOptions = valuesOptions;
2104
+
2092
2105
  /**
2093
2106
  * Reserved ranges, if any.
2094
2107
  * @type {Array.<number[]|string>}
@@ -2133,11 +2146,12 @@ Enum.fromJSON = function fromJSON(name, json) {
2133
2146
  Enum.prototype.toJSON = function toJSON(toJSONOptions) {
2134
2147
  var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
2135
2148
  return util.toObject([
2136
- "options" , this.options,
2137
- "values" , this.values,
2138
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
2139
- "comment" , keepComments ? this.comment : undefined,
2140
- "comments" , keepComments ? this.comments : undefined
2149
+ "options" , this.options,
2150
+ "valuesOptions" , this.valuesOptions,
2151
+ "values" , this.values,
2152
+ "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
2153
+ "comment" , keepComments ? this.comment : undefined,
2154
+ "comments" , keepComments ? this.comments : undefined
2141
2155
  ]);
2142
2156
  };
2143
2157
 
@@ -2146,11 +2160,12 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
2146
2160
  * @param {string} name Value name
2147
2161
  * @param {number} id Value id
2148
2162
  * @param {string} [comment] Comment, if any
2163
+ * @param {Object.<string, *>|undefined} [options] Options, if any
2149
2164
  * @returns {Enum} `this`
2150
2165
  * @throws {TypeError} If arguments are invalid
2151
2166
  * @throws {Error} If there is already a value with this name or id
2152
2167
  */
2153
- Enum.prototype.add = function add(name, id, comment) {
2168
+ Enum.prototype.add = function add(name, id, comment, options) {
2154
2169
  // utilized by the parser but not by .fromJSON
2155
2170
 
2156
2171
  if (!util.isString(name))
@@ -2175,6 +2190,12 @@ Enum.prototype.add = function add(name, id, comment) {
2175
2190
  } else
2176
2191
  this.valuesById[this.values[name] = id] = name;
2177
2192
 
2193
+ if (options) {
2194
+ if (this.valuesOptions === undefined)
2195
+ this.valuesOptions = {};
2196
+ this.valuesOptions[name] = options || null;
2197
+ }
2198
+
2178
2199
  this.comments[name] = comment || null;
2179
2200
  return this;
2180
2201
  };
@@ -2198,6 +2219,8 @@ Enum.prototype.remove = function remove(name) {
2198
2219
  delete this.valuesById[val];
2199
2220
  delete this.values[name];
2200
2221
  delete this.comments[name];
2222
+ if (this.valuesOptions)
2223
+ delete this.valuesOptions[name];
2201
2224
 
2202
2225
  return this;
2203
2226
  };
@@ -3196,7 +3219,8 @@ var ReflectionObject = require(24);
3196
3219
  ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
3197
3220
 
3198
3221
  var Field = require(16),
3199
- util = require(37);
3222
+ util = require(37),
3223
+ OneOf = require(25);
3200
3224
 
3201
3225
  var Type, // cyclic
3202
3226
  Service,
@@ -3407,7 +3431,7 @@ Namespace.prototype.getEnum = function getEnum(name) {
3407
3431
  */
3408
3432
  Namespace.prototype.add = function add(object) {
3409
3433
 
3410
- if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3434
+ if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3411
3435
  throw TypeError("object must be a valid nested object");
3412
3436
 
3413
3437
  if (!this.nested)
@@ -3622,7 +3646,7 @@ Namespace._configure = function(Type_, Service_, Enum_) {
3622
3646
  Enum = Enum_;
3623
3647
  };
3624
3648
 
3625
- },{"16":16,"24":24,"37":37}],24:[function(require,module,exports){
3649
+ },{"16":16,"24":24,"25":25,"37":37}],24:[function(require,module,exports){
3626
3650
  "use strict";
3627
3651
  module.exports = ReflectionObject;
3628
3652
 
@@ -4518,6 +4542,14 @@ function parse(source, root, options) {
4518
4542
  }
4519
4543
  break;
4520
4544
 
4545
+ case "message":
4546
+ parseType(type, token);
4547
+ break;
4548
+
4549
+ case "enum":
4550
+ parseEnum(type, token);
4551
+ break;
4552
+
4521
4553
  /* istanbul ignore next */
4522
4554
  default:
4523
4555
  throw illegal(token); // there are no groups with proto3 semantics
@@ -4618,7 +4650,14 @@ function parse(source, root, options) {
4618
4650
 
4619
4651
  skip("=");
4620
4652
  var value = parseId(next(), true),
4621
- dummy = {};
4653
+ dummy = {
4654
+ options: undefined
4655
+ };
4656
+ dummy.setOption = function(name, value) {
4657
+ if (this.options === undefined)
4658
+ this.options = {};
4659
+ this.options[name] = value;
4660
+ };
4622
4661
  ifBlock(dummy, function parseEnumValue_block(token) {
4623
4662
 
4624
4663
  /* istanbul ignore else */
@@ -4631,7 +4670,7 @@ function parse(source, root, options) {
4631
4670
  }, function parseEnumValue_line() {
4632
4671
  parseInlineOptions(dummy); // skip
4633
4672
  });
4634
- parent.add(token, value, dummy.comment);
4673
+ parent.add(token, value, dummy.comment, dummy.options);
4635
4674
  }
4636
4675
 
4637
4676
  function parseOption(parent, token) {