protobufjs 8.6.1 → 8.6.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.
package/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.6.1 (c) 2016, daniel wirtz
3
- * compiled sun, 07 jun 2026 00:06:12 utc
2
+ * protobuf.js v8.6.3 (c) 2016, daniel wirtz
3
+ * compiled thu, 11 jun 2026 00:02:30 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -405,9 +405,9 @@ common("field_mask", {
405
405
 
406
406
  /**
407
407
  * Properties of a google.protobuf.FieldMask message.
408
- * @interface IDoubleValue
408
+ * @interface IFieldMask
409
409
  * @type {Object}
410
- * @property {number} [value]
410
+ * @property {string[]} [paths]
411
411
  * @memberof common
412
412
  */
413
413
  FieldMask: {
@@ -798,6 +798,10 @@ function missing(field) {
798
798
  return "missing required '" + field.name + "'";
799
799
  }
800
800
 
801
+ function stringMethod(field) {
802
+ return field._features.utf8_validation === "VERIFY" ? "stringVerify" : "string";
803
+ }
804
+
801
805
  /**
802
806
  * Generates a decoder specific to the specified message type.
803
807
  * @param {Type} mtype Message type
@@ -867,7 +871,7 @@ function decoder(mtype) {
867
871
  ("case 1:")
868
872
  ("if(u!==%i)", types.mapKey[field.keyType])
869
873
  ("break")
870
- ("k=r.%s()", field.keyType)
874
+ ("k=r.%s()", field.keyType === "string" ? stringMethod(field) : field.keyType)
871
875
  ("continue")
872
876
  ("case 2:")
873
877
  ("if(u!==%i)", types.basic[type] === undefined ? 2 : types.basic[type])
@@ -876,7 +880,7 @@ function decoder(mtype) {
876
880
  if (types.basic[type] === undefined) gen
877
881
  ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
878
882
  else gen
879
- ("v=r.%s()", type);
883
+ ("v=r.%s()", type === "string" ? stringMethod(field) : type);
880
884
 
881
885
  gen
882
886
  ("continue")
@@ -923,7 +927,7 @@ function decoder(mtype) {
923
927
  else gen
924
928
  ("%s.push(types[%i].decode(r,r.uint32(),undefined,q+1))", ref, i);
925
929
  } else gen
926
- ("%s.push(r.%s())", ref, type);
930
+ ("%s.push(r.%s())", ref, type === "string" ? stringMethod(field) : type);
927
931
 
928
932
  // Non-repeated
929
933
  } else if (types.basic[type] === undefined) {
@@ -941,7 +945,7 @@ function decoder(mtype) {
941
945
  ("case %i:{", field.id)
942
946
  ("if(u!==%i)", types.basic[type])
943
947
  ("break")
944
- ("%s=r.%s()", ref, type);
948
+ ("%s=r.%s()", ref, type === "string" ? stringMethod(field) : type);
945
949
  } else {
946
950
  gen
947
951
  ("case %i:{", field.id)
@@ -951,7 +955,9 @@ function decoder(mtype) {
951
955
  // TODO: Protoc rejects open enums whose first value is not zero.
952
956
  // We should do the same, but for v8 this would be a regression.
953
957
  ("if((v=r.%s())!==%j)", type, field.typeDefault);
954
- else if (type === "string" || type === "bytes") gen
958
+ else if (type === "string") gen
959
+ ("if((v=r.%s()).length)", stringMethod(field));
960
+ else if (type === "bytes") gen
955
961
  ("if((v=r.%s()).length)", type);
956
962
  else if (types.long[type] !== undefined) gen
957
963
  ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
@@ -1843,9 +1849,9 @@ Field._configure = function configure(Type_) {
1843
1849
 
1844
1850
  },{"15":15,"27":27,"28":28,"6":6}],8:[function(require,module,exports){
1845
1851
  "use strict";
1846
- var protobuf = module.exports = require(9);
1852
+ exports = module.exports = require(9);
1847
1853
 
1848
- protobuf.build = "light";
1854
+ exports.build = "light";
1849
1855
 
1850
1856
  /**
1851
1857
  * A node-style callback as used by {@link load} and {@link Root#load}.
@@ -1867,9 +1873,9 @@ protobuf.build = "light";
1867
1873
  function load(filename, root, callback) {
1868
1874
  if (typeof root === "function") {
1869
1875
  callback = root;
1870
- root = new protobuf.Root();
1876
+ root = new exports.Root();
1871
1877
  } else if (!root)
1872
- root = new protobuf.Root();
1878
+ root = new exports.Root();
1873
1879
  return root.load(filename, callback);
1874
1880
  }
1875
1881
 
@@ -1897,7 +1903,7 @@ function load(filename, root, callback) {
1897
1903
  */
1898
1904
  // function load(filename:string, [root:Root]):Promise<Root>
1899
1905
 
1900
- protobuf.load = load;
1906
+ exports.load = load;
1901
1907
 
1902
1908
  /**
1903
1909
  * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
@@ -1909,47 +1915,46 @@ protobuf.load = load;
1909
1915
  */
1910
1916
  function loadSync(filename, root) {
1911
1917
  if (!root)
1912
- root = new protobuf.Root();
1918
+ root = new exports.Root();
1913
1919
  return root.loadSync(filename);
1914
1920
  }
1915
1921
 
1916
- protobuf.loadSync = loadSync;
1922
+ exports.loadSync = loadSync;
1917
1923
 
1918
1924
  // Serialization
1919
- protobuf.encoder = require(5);
1920
- protobuf.decoder = require(4);
1921
- protobuf.verifier = require(42);
1922
- protobuf.converter = require(3);
1925
+ exports.encoder = require(5);
1926
+ exports.decoder = require(4);
1927
+ exports.verifier = require(42);
1928
+ exports.converter = require(3);
1923
1929
 
1924
1930
  // Reflection
1925
- protobuf.ReflectionObject = require(15);
1926
- protobuf.Namespace = require(14);
1927
- protobuf.Root = require(20);
1928
- protobuf.Enum = require(6);
1929
- protobuf.Type = require(26);
1930
- protobuf.Field = require(7);
1931
- protobuf.OneOf = require(16);
1932
- protobuf.MapField = require(11);
1933
- protobuf.Service = require(24);
1934
- protobuf.Method = require(13);
1931
+ exports.ReflectionObject = require(15);
1932
+ exports.Namespace = require(14);
1933
+ exports.Root = require(20);
1934
+ exports.Enum = require(6);
1935
+ exports.Type = require(26);
1936
+ exports.Field = require(7);
1937
+ exports.OneOf = require(16);
1938
+ exports.MapField = require(11);
1939
+ exports.Service = require(24);
1940
+ exports.Method = require(13);
1935
1941
 
1936
1942
  // Runtime
1937
- protobuf.Message = require(12);
1938
- protobuf.wrappers = require(43);
1943
+ exports.Message = require(12);
1944
+ exports.wrappers = require(43);
1939
1945
 
1940
1946
  // Utility
1941
- protobuf.types = require(27);
1942
- protobuf.util = require(28);
1947
+ exports.types = require(27);
1948
+ exports.util = require(28);
1943
1949
 
1944
1950
  // Set up possibly cyclic reflection dependencies
1945
- protobuf.ReflectionObject._configure(protobuf.Root);
1946
- protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
1947
- protobuf.Root._configure(protobuf.Type, undefined, {});
1948
- protobuf.Field._configure(protobuf.Type);
1951
+ exports.ReflectionObject._configure(exports.Root);
1952
+ exports.Namespace._configure(exports.Type, exports.Service, exports.Enum);
1953
+ exports.Root._configure(exports.Type, undefined, {});
1954
+ exports.Field._configure(exports.Type);
1949
1955
 
1950
1956
  },{"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"20":20,"24":24,"26":26,"27":27,"28":28,"3":3,"4":4,"42":42,"43":43,"5":5,"6":6,"7":7,"9":9}],9:[function(require,module,exports){
1951
1957
  "use strict";
1952
- var protobuf = exports;
1953
1958
 
1954
1959
  /**
1955
1960
  * Build type, one of `"full"`, `"light"` or `"minimal"`.
@@ -1957,19 +1962,19 @@ var protobuf = exports;
1957
1962
  * @type {string}
1958
1963
  * @const
1959
1964
  */
1960
- protobuf.build = "minimal";
1965
+ exports.build = "minimal";
1961
1966
 
1962
1967
  // Serialization
1963
- protobuf.Writer = require(44);
1964
- protobuf.BufferWriter = require(45);
1965
- protobuf.Reader = require(18);
1966
- protobuf.BufferReader = require(19);
1968
+ exports.Writer = require(44);
1969
+ exports.BufferWriter = require(45);
1970
+ exports.Reader = require(18);
1971
+ exports.BufferReader = require(19);
1967
1972
 
1968
1973
  // Utility
1969
- protobuf.util = require(37);
1970
- protobuf.rpc = require(22);
1971
- protobuf.roots = require(21);
1972
- protobuf.configure = configure;
1974
+ exports.util = require(37);
1975
+ exports.rpc = require(22);
1976
+ exports.roots = require(21);
1977
+ exports.configure = configure;
1973
1978
 
1974
1979
  /* istanbul ignore next */
1975
1980
  /**
@@ -1977,9 +1982,9 @@ protobuf.configure = configure;
1977
1982
  * @returns {undefined}
1978
1983
  */
1979
1984
  function configure() {
1980
- protobuf.util._configure();
1981
- protobuf.Writer._configure(protobuf.BufferWriter);
1982
- protobuf.Reader._configure(protobuf.BufferReader);
1985
+ exports.util._configure();
1986
+ exports.Writer._configure(exports.BufferWriter);
1987
+ exports.Reader._configure(exports.BufferReader);
1983
1988
  }
1984
1989
 
1985
1990
  // Set up buffer utility according to the environment
@@ -1987,17 +1992,17 @@ configure();
1987
1992
 
1988
1993
  },{"18":18,"19":19,"21":21,"22":22,"37":37,"44":44,"45":45}],10:[function(require,module,exports){
1989
1994
  "use strict";
1990
- var protobuf = module.exports = require(8);
1995
+ exports = module.exports = require(8);
1991
1996
 
1992
- protobuf.build = "full";
1997
+ exports.build = "full";
1993
1998
 
1994
1999
  // Parser
1995
- protobuf.tokenize = require(25);
1996
- protobuf.parse = require(17);
1997
- protobuf.common = require(2);
2000
+ exports.tokenize = require(25);
2001
+ exports.parse = require(17);
2002
+ exports.common = require(2);
1998
2003
 
1999
2004
  // Configure parser
2000
- protobuf.Root._configure(protobuf.Type, protobuf.parse, protobuf.common);
2005
+ exports.Root._configure(exports.Type, exports.parse, exports.common);
2001
2006
 
2002
2007
  },{"17":17,"2":2,"25":25,"8":8}],11:[function(require,module,exports){
2003
2008
  "use strict";
@@ -2148,7 +2153,7 @@ var util = require(37);
2148
2153
  * @classdesc Abstract runtime message.
2149
2154
  * @constructor
2150
2155
  * @param {Properties<T>} [properties] Properties to set
2151
- * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
2156
+ * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding when enabled
2152
2157
  * @template T extends object = object
2153
2158
  */
2154
2159
  function Message(properties) {
@@ -2777,7 +2782,8 @@ Namespace.prototype.remove = function remove(object) {
2777
2782
  if (object.parent !== this)
2778
2783
  throw Error(object + " is not a member of " + this);
2779
2784
 
2780
- delete this.nested[object.name];
2785
+ if (!util.remove(this.nested, object, object.name))
2786
+ throw Error(object + " is not a member of " + this);
2781
2787
  if (!Object.keys(this.nested).length)
2782
2788
  this.nested = undefined;
2783
2789
 
@@ -4928,18 +4934,16 @@ function readLongVarint() {
4928
4934
  return bits;
4929
4935
  i = 0;
4930
4936
  } else {
4931
- for (; i < 3; ++i) {
4937
+ for (; i < 4; ++i) {
4932
4938
  /* istanbul ignore if */
4933
4939
  if (this.pos >= this.len)
4934
4940
  throw indexOutOfRange(this);
4935
- // 1st..3th
4941
+ // 1st..4th
4936
4942
  bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
4937
4943
  if (this.buf[this.pos++] < 128)
4938
4944
  return bits;
4939
4945
  }
4940
- // 4th
4941
- bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
4942
- return bits;
4946
+ throw indexOutOfRange(this);
4943
4947
  }
4944
4948
  if (this.len - this.pos > 4) { // fast route (hi)
4945
4949
  for (; i < 5; ++i) {
@@ -5133,6 +5137,23 @@ Reader.prototype.string = function read_string() {
5133
5137
  return utf8.read(this.buf, start, end);
5134
5138
  };
5135
5139
 
5140
+ /**
5141
+ * Reads a string preceeded by its byte length as a varint, rejecting invalid UTF8.
5142
+ * @returns {string} Value read
5143
+ */
5144
+ Reader.prototype.stringVerify = function read_string_verify() {
5145
+ var length = this.uint32(),
5146
+ start = this.pos,
5147
+ end = this.pos + length;
5148
+
5149
+ /* istanbul ignore if */
5150
+ if (end > this.len)
5151
+ throw indexOutOfRange(this, length);
5152
+
5153
+ this.pos = end;
5154
+ return utf8.readStrict(this.buf, start, end);
5155
+ };
5156
+
5136
5157
  /**
5137
5158
  * Skips the specified number of bytes if specified, otherwise skips a varint.
5138
5159
  * @param {number} [length] Length if known, otherwise a varint is assumed
@@ -5164,7 +5185,7 @@ Reader.recursionLimit = util.recursionLimit;
5164
5185
  * Whether readers discard unknown fields while decoding.
5165
5186
  * @type {boolean}
5166
5187
  */
5167
- Reader.discardUnknown = false;
5188
+ Reader.discardUnknown = true;
5168
5189
 
5169
5190
  /**
5170
5191
  * Skips the next element of the specified wire type.
@@ -6727,6 +6748,7 @@ Object.defineProperties(Type.prototype, {
6727
6748
  /**
6728
6749
  * The registered constructor, if any registered, otherwise a generic constructor.
6729
6750
  * Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
6751
+ * When assigning manually, add the type to its parent namespace/root first if fields reference other reflected types, because constructor setup resolves field defaults.
6730
6752
  * @name Type#ctor
6731
6753
  * @type {Constructor<{}>}
6732
6754
  */
@@ -6996,10 +7018,9 @@ Type.prototype.remove = function remove(object) {
6996
7018
  // See Type#add for the reason why extension fields are excluded here.
6997
7019
 
6998
7020
  /* istanbul ignore if */
6999
- if (!this.fields || this.fields[object.name] !== object)
7021
+ if (!util.remove(this.fields, object, object.name))
7000
7022
  throw Error(object + " is not a member of " + this);
7001
7023
 
7002
- delete this.fields[object.name];
7003
7024
  object.parent = null;
7004
7025
  object.onRemove(this);
7005
7026
  return clearCache(this);
@@ -7007,10 +7028,9 @@ Type.prototype.remove = function remove(object) {
7007
7028
  if (object instanceof OneOf) {
7008
7029
 
7009
7030
  /* istanbul ignore if */
7010
- if (!this.oneofs || this.oneofs[object.name] !== object)
7031
+ if (!util.remove(this.oneofs, object, object.name))
7011
7032
  throw Error(object + " is not a member of " + this);
7012
7033
 
7013
- delete this.oneofs[object.name];
7014
7034
  object.parent = null;
7015
7035
  object.onRemove(this);
7016
7036
  return clearCache(this);
@@ -7485,6 +7505,28 @@ util.toObject = function toObject(array) {
7485
7505
  return object;
7486
7506
  };
7487
7507
 
7508
+ /**
7509
+ * Removes the first matching value from an object.
7510
+ * @param {Object.<string,*>|undefined} object Object to remove from
7511
+ * @param {*} value Value to remove
7512
+ * @param {string} [key] Optional key for fast path removal
7513
+ * @returns {boolean} `true` if removed, otherwise `false`
7514
+ */
7515
+ util.remove = function remove(object, value, key) {
7516
+ if (!object)
7517
+ return false;
7518
+ if (key !== undefined && Object.prototype.hasOwnProperty.call(object, key) && object[key] === value) {
7519
+ delete object[key];
7520
+ return true;
7521
+ }
7522
+ for (var names = Object.keys(object), i = 0; i < names.length; ++i)
7523
+ if (object[names[i]] === value) {
7524
+ delete object[names[i]];
7525
+ return true;
7526
+ }
7527
+ return false;
7528
+ };
7529
+
7488
7530
  /**
7489
7531
  * Tests whether the specified name is a reserved word in JS.
7490
7532
  * @param {string} name Name to test
@@ -9266,6 +9308,28 @@ util._configure = function() {
9266
9308
  */
9267
9309
  var path = exports;
9268
9310
 
9311
+ var urlRe = /^[a-zA-Z][a-zA-Z0-9+.-]+:\/\//;
9312
+
9313
+ function normalizeUrl(path) {
9314
+ if (typeof URL === "undefined" || !urlRe.test(path))
9315
+ return null;
9316
+ try {
9317
+ return new URL(path).href;
9318
+ } catch (e) {
9319
+ return null;
9320
+ }
9321
+ }
9322
+
9323
+ function resolveUrl(originPath, includePath) {
9324
+ if (typeof URL === "undefined" || !urlRe.test(originPath) || urlRe.test(includePath))
9325
+ return null;
9326
+ try {
9327
+ return new URL(includePath, originPath).href;
9328
+ } catch (e) {
9329
+ return null;
9330
+ }
9331
+ }
9332
+
9269
9333
  var isAbsolute =
9270
9334
  /**
9271
9335
  * Tests if the specified path is absolute.
@@ -9283,6 +9347,9 @@ var normalize =
9283
9347
  * @returns {string} Normalized path
9284
9348
  */
9285
9349
  path.normalize = function normalize(path) {
9350
+ var normalizedUrl = normalizeUrl(path);
9351
+ if (normalizedUrl)
9352
+ return normalizedUrl;
9286
9353
  var firstTwoCharacters = path.substring(0,2);
9287
9354
  var uncPrefix = "";
9288
9355
  if (firstTwoCharacters === "\\\\") {
@@ -9321,8 +9388,11 @@ path.normalize = function normalize(path) {
9321
9388
  * @returns {string} Path to the include file
9322
9389
  */
9323
9390
  path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
9391
+ var resolvedUrl = resolveUrl(originPath, includePath);
9392
+ if (resolvedUrl)
9393
+ return resolvedUrl;
9324
9394
  if (!alreadyNormalized)
9325
- includePath = normalize(includePath);
9395
+ includePath = normalize(includePath); // path or absolute url
9326
9396
  if (isAbsolute(includePath))
9327
9397
  return includePath;
9328
9398
  if (!alreadyNormalized)
@@ -9398,7 +9468,8 @@ function pool(alloc, slice, size) {
9398
9468
  * @namespace
9399
9469
  */
9400
9470
  var utf8 = exports,
9401
- replacementChar = "\ufffd";
9471
+ replacementChar = "\ufffd",
9472
+ strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
9402
9473
 
9403
9474
  /**
9404
9475
  * Calculates the UTF8 byte length of a string.
@@ -9487,6 +9558,56 @@ utf8.read = function utf8_read_ascii(buffer, start, end) {
9487
9558
  return str;
9488
9559
  };
9489
9560
 
9561
+ function utf8_read_strict(buffer, start, end) {
9562
+ var source = start === 0 && end === buffer.length
9563
+ ? buffer
9564
+ : buffer.subarray
9565
+ ? buffer.subarray(start, end)
9566
+ : buffer.slice(start, end);
9567
+ if (Array.isArray(source))
9568
+ source = Uint8Array.from(source);
9569
+ return strictDecoder.decode(source);
9570
+ }
9571
+
9572
+ /**
9573
+ * Reads UTF8 bytes as a string, rejecting invalid UTF8.
9574
+ * @param {Uint8Array} buffer Source buffer
9575
+ * @param {number} start Source start
9576
+ * @param {number} end Source end
9577
+ * @returns {string} String read
9578
+ */
9579
+ utf8.readStrict = function utf8_read_strict_ascii(buffer, start, end) {
9580
+ if (end - start < 1)
9581
+ return "";
9582
+
9583
+ var str = "",
9584
+ i = start,
9585
+ c1, c2, c3, c4, c5, c6, c7, c8;
9586
+
9587
+ for (; i + 7 < end; i += 8) {
9588
+ c1 = buffer[i];
9589
+ c2 = buffer[i + 1];
9590
+ c3 = buffer[i + 2];
9591
+ c4 = buffer[i + 3];
9592
+ c5 = buffer[i + 4];
9593
+ c6 = buffer[i + 5];
9594
+ c7 = buffer[i + 6];
9595
+ c8 = buffer[i + 7];
9596
+ if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
9597
+ return str + utf8_read_strict(buffer, i, end);
9598
+ str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
9599
+ }
9600
+
9601
+ for (; i < end; ++i) {
9602
+ c1 = buffer[i];
9603
+ if (c1 & 0x80)
9604
+ return str + utf8_read_strict(buffer, i, end);
9605
+ str += String.fromCharCode(c1);
9606
+ }
9607
+
9608
+ return str;
9609
+ };
9610
+
9490
9611
  /**
9491
9612
  * Writes a string as UTF8 bytes.
9492
9613
  * @param {string} string Source string