protobufjs 8.4.1 → 8.5.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 v8.4.1 (c) 2016, daniel wirtz
3
- * compiled thu, 21 may 2026 18:52:08 utc
2
+ * protobuf.js v8.5.0 (c) 2016, daniel wirtz
3
+ * compiled fri, 29 may 2026 22:57:25 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -485,7 +485,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
485
485
  } gen
486
486
  ("}");
487
487
  } else gen
488
- ("if(typeof d%s!==\"object\")", prop)
488
+ ("if(!util.isObject(d%s))", prop)
489
489
  ("throw TypeError(%j)", field.fullName + ": object expected")
490
490
  ("m%s=types[%i].fromObject(d%s,q+1)", prop, fieldIndex, prop);
491
491
  } else {
@@ -552,6 +552,8 @@ converter.fromObject = function fromObject(mtype) {
552
552
  var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
553
553
  ("if(d instanceof C)")
554
554
  ("return d")
555
+ ("if(!util.isObject(d))")
556
+ ("throw TypeError(%j)", mtype.fullName + ": object expected")
555
557
  ("if(q===undefined)q=0")
556
558
  ("if(q>util.recursionLimit)")
557
559
  ("throw Error(\"max depth exceeded\")");
@@ -568,7 +570,7 @@ converter.fromObject = function fromObject(mtype) {
568
570
  // Map fields
569
571
  if (field.map) { gen
570
572
  ("if(d%s){", prop)
571
- ("if(typeof d%s!==\"object\")", prop)
573
+ ("if(!util.isObject(d%s))", prop)
572
574
  ("throw TypeError(%j)", field.fullName + ": object expected")
573
575
  ("m%s={}", prop)
574
576
  ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
@@ -973,8 +975,10 @@ function decoder(mtype) {
973
975
  // Unknown fields
974
976
  gen
975
977
  ("r.skipType(%s,q,t)", i ? "u" : "t&7")
976
- ("util.makeProp(m,\"$unknowns\",false);")
977
- ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
978
+ ("if(!r.discardUnknown){")
979
+ ("util.makeProp(m,\"$unknowns\",false);")
980
+ ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
981
+ ("}")
978
982
  ("}")
979
983
  ("if(z!==undefined)")
980
984
  ("throw Error(\"missing end group\")");
@@ -2285,7 +2289,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
2285
2289
 
2286
2290
  /**
2287
2291
  * Whether requests are streamed or not.
2288
- * @type {boolean|undefined}
2292
+ * @type {true|undefined}
2289
2293
  */
2290
2294
  this.requestStream = requestStream ? true : undefined; // toJSON
2291
2295
 
@@ -2297,10 +2301,16 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
2297
2301
 
2298
2302
  /**
2299
2303
  * Whether responses are streamed or not.
2300
- * @type {boolean|undefined}
2304
+ * @type {true|undefined}
2301
2305
  */
2302
2306
  this.responseStream = responseStream ? true : undefined; // toJSON
2303
2307
 
2308
+ /**
2309
+ * gRPC-style method path.
2310
+ * @type {string}
2311
+ */
2312
+ this.path = "/" + this.name;
2313
+
2304
2314
  /**
2305
2315
  * Resolved request type.
2306
2316
  * @type {Type|null}
@@ -2378,6 +2388,14 @@ Method.prototype.resolve = function resolve() {
2378
2388
  if (this.resolved)
2379
2389
  return this;
2380
2390
 
2391
+ if (this.parent) {
2392
+ var serviceName = this.parent.fullName;
2393
+ if (serviceName.charAt(0) === ".")
2394
+ serviceName = serviceName.substring(1);
2395
+ this.path = "/" + serviceName + "/" + this.name;
2396
+ } else
2397
+ this.path = "/" + this.name;
2398
+
2381
2399
  this.resolvedRequestType = this.parent.lookupType(this.requestType);
2382
2400
  this.resolvedResponseType = this.parent.lookupType(this.responseType);
2383
2401
 
@@ -2455,7 +2473,7 @@ Namespace.arrayToJSON = arrayToJSON;
2455
2473
  Namespace.isReservedId = function isReservedId(reserved, id) {
2456
2474
  if (reserved)
2457
2475
  for (var i = 0; i < reserved.length; ++i)
2458
- if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] > id)
2476
+ if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] >= id)
2459
2477
  return true;
2460
2478
  return false;
2461
2479
  };
@@ -2813,14 +2831,14 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
2813
2831
  if (path[0] === "")
2814
2832
  return this.root.lookup(path.slice(1), filterTypes);
2815
2833
 
2816
- // Early bailout for objects with matching absolute paths
2817
- var found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
2834
+ // Lookup at this namespace and below
2835
+ var found = this._lookupImpl(path, flatPath);
2818
2836
  if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
2819
2837
  return found;
2820
2838
  }
2821
2839
 
2822
- // Do a regular lookup at this namespace and below
2823
- found = this._lookupImpl(path, flatPath);
2840
+ // Fall back to respective absolute path once relative scope has been checked (non-standard)
2841
+ found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
2824
2842
  if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
2825
2843
  return found;
2826
2844
  }
@@ -3592,6 +3610,9 @@ var base10Re = /^[1-9][0-9]*$/,
3592
3610
  nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
3593
3611
  typeRefRe = util.patterns.typeRefRe;
3594
3612
 
3613
+ var maxFieldId = 536870911, // 2^29 - 1
3614
+ maxEnumId = 2147483647; // 2^31 - 1
3615
+
3595
3616
  /**
3596
3617
  * Result object returned from {@link parse}.
3597
3618
  * @interface IParserResult
@@ -3711,7 +3732,7 @@ function parse(source, root, options) {
3711
3732
  }
3712
3733
  }
3713
3734
 
3714
- function readRanges(target, acceptStrings) {
3735
+ function readRanges(target, acceptStrings, max, acceptNegative) {
3715
3736
  var token, start;
3716
3737
  do {
3717
3738
  if (acceptStrings && ((token = peek()) === "\"" || token === "'")) {
@@ -3722,7 +3743,7 @@ function parse(source, root, options) {
3722
3743
  }
3723
3744
  } else {
3724
3745
  try {
3725
- target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]);
3746
+ target.push([ start = parseId(next(), acceptNegative, max), skip("to", true) ? parseId(next(), acceptNegative, max) : start ]);
3726
3747
  } catch (err) {
3727
3748
  if (acceptStrings && typeRefRe.test(token) && edition >= 2023) {
3728
3749
  target.push(token);
@@ -3781,10 +3802,10 @@ function parse(source, root, options) {
3781
3802
  throw illegal(token, "number", insideTryCatch);
3782
3803
  }
3783
3804
 
3784
- function parseId(token, acceptNegative) {
3805
+ function parseId(token, acceptNegative, max) {
3785
3806
  switch (token) {
3786
3807
  case "max": case "MAX": case "Max":
3787
- return 536870911;
3808
+ return max || maxFieldId;
3788
3809
  case "0":
3789
3810
  return 0;
3790
3811
  }
@@ -4242,7 +4263,7 @@ function parse(source, root, options) {
4242
4263
  break;
4243
4264
 
4244
4265
  case "reserved":
4245
- readRanges(enm.reserved || (enm.reserved = []), true);
4266
+ readRanges(enm.reserved || (enm.reserved = []), true, maxEnumId, true);
4246
4267
  if(enm.reserved === undefined) enm.reserved = [];
4247
4268
  break;
4248
4269
 
@@ -4656,6 +4677,12 @@ function Reader(buffer) {
4656
4677
  * @type {number}
4657
4678
  */
4658
4679
  this.len = buffer.length;
4680
+
4681
+ /**
4682
+ * Whether to discard unknown fields while decoding.
4683
+ * @type {boolean}
4684
+ */
4685
+ this.discardUnknown = Reader.discardUnknown;
4659
4686
  }
4660
4687
 
4661
4688
  var create_array = typeof Uint8Array !== "undefined"
@@ -5068,6 +5095,12 @@ Reader.prototype.skip = function skip(length) {
5068
5095
  */
5069
5096
  Reader.recursionLimit = util.recursionLimit;
5070
5097
 
5098
+ /**
5099
+ * Whether readers discard unknown fields while decoding.
5100
+ * @type {boolean}
5101
+ */
5102
+ Reader.discardUnknown = false;
5103
+
5071
5104
  /**
5072
5105
  * Skips the next element of the specified wire type.
5073
5106
  * @param {number} wireType Wire type received
@@ -5642,7 +5675,7 @@ Root._configure = function(Type_, parse_, common_) {
5642
5675
 
5643
5676
  },{"14":14,"16":16,"28":28,"6":6,"7":7}],21:[function(require,module,exports){
5644
5677
  "use strict";
5645
- module.exports = {};
5678
+ module.exports = Object.create(null);
5646
5679
 
5647
5680
  /**
5648
5681
  * Named roots.
@@ -5724,10 +5757,16 @@ var util = require(38);
5724
5757
  * @typedef rpc.ServiceMethod
5725
5758
  * @template TReq extends Message<TReq>
5726
5759
  * @template TRes extends Message<TRes>
5727
- * @type {function}
5728
- * @param {TReq|Properties<TReq>} request Request message or plain object
5729
- * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
5730
- * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
5760
+ * @type {{
5761
+ * (request: TReq|Properties<TReq>, callback: rpc.ServiceMethodCallback<TRes>): void;
5762
+ * (request: TReq|Properties<TReq>): Promise<TRes>;
5763
+ * readonly name: string;
5764
+ * readonly path: string;
5765
+ * readonly requestType: string;
5766
+ * readonly responseType: string;
5767
+ * readonly requestStream: true|undefined;
5768
+ * readonly responseStream: true|undefined;
5769
+ * }}
5731
5770
  */
5732
5771
 
5733
5772
  /**
@@ -9953,7 +9992,7 @@ Writer.prototype.uint32 = function write_uint32(value) {
9953
9992
  * @returns {Writer} `this`
9954
9993
  */
9955
9994
  Writer.prototype.int32 = function write_int32(value) {
9956
- return value < 0
9995
+ return (value |= 0) < 0
9957
9996
  ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
9958
9997
  : this.uint32(value);
9959
9998
  };
@@ -9968,16 +10007,18 @@ Writer.prototype.sint32 = function write_sint32(value) {
9968
10007
  };
9969
10008
 
9970
10009
  function writeVarint64(val, buf, pos) {
9971
- while (val.hi) {
9972
- buf[pos++] = val.lo & 127 | 128;
9973
- val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
9974
- val.hi >>>= 7;
9975
- }
9976
- while (val.lo > 127) {
9977
- buf[pos++] = val.lo & 127 | 128;
9978
- val.lo = val.lo >>> 7;
9979
- }
9980
- buf[pos++] = val.lo;
10010
+ var lo = val.lo,
10011
+ hi = val.hi;
10012
+ while (hi) {
10013
+ buf[pos++] = lo & 127 | 128;
10014
+ lo = (lo >>> 7 | hi << 25) >>> 0;
10015
+ hi >>>= 7;
10016
+ }
10017
+ while (lo > 127) {
10018
+ buf[pos++] = lo & 127 | 128;
10019
+ lo = lo >>> 7;
10020
+ }
10021
+ buf[pos++] = lo;
9981
10022
  }
9982
10023
 
9983
10024
  /**