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/README.md CHANGED
@@ -76,7 +76,7 @@ const decoded = AwesomeMessage.decode(encoded);
76
76
 
77
77
  Plain objects can be encoded directly when they already use protobuf.js runtime types: numbers for 32-bit numeric fields, booleans for `bool`, strings for `string`, `Uint8Array` or `Buffer` for `bytes`, arrays for repeated fields, and plain objects for maps. Map keys are the string representation of the respective value or an 8-character hash string for 64-bit keys.
78
78
 
79
- Unknown fields present on the wire are preserved by default in `message.$unknowns` and forwarded when the message is re-encoded. Unknown field data can be dropped from a decoded message with `delete message.$unknowns`, discarded during decode with `reader.discardUnknown = true` per reader, or disabled by default for subsequently created readers with `Reader.discardUnknown = true`.
79
+ Unknown fields present on the wire are discarded by default. To preserve and forward unknown fields, set `reader.discardUnknown = false` before decoding with that reader, or make this the default for subsequently created readers with `Reader.discardUnknown = false`. Preserved unknown field data can be dropped from a decoded message with `delete message.$unknowns`.
80
80
 
81
81
  ### Convert plain objects
82
82
 
@@ -292,7 +292,7 @@ const decoded = AwesomeMessage.decode(bytes);
292
292
  decoded.customInstanceMethod(); // string
293
293
  ```
294
294
 
295
- protobuf.js will populate the constructor with the usual static runtime methods and use it for decoded messages. In TypeScript, custom members are visible when using the custom class type in consuming code.
295
+ protobuf.js will populate the constructor with the usual static runtime methods and use it for decoded messages. When assigning constructors manually, add the type to its parent namespace/root first if fields reference other reflected types. In TypeScript, custom members are visible when using the custom class type in consuming code.
296
296
 
297
297
  ### Services
298
298
 
@@ -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
  */
@@ -397,6 +397,10 @@ function missing(field) {
397
397
  return "missing required '" + field.name + "'";
398
398
  }
399
399
 
400
+ function stringMethod(field) {
401
+ return field._features.utf8_validation === "VERIFY" ? "stringVerify" : "string";
402
+ }
403
+
400
404
  /**
401
405
  * Generates a decoder specific to the specified message type.
402
406
  * @param {Type} mtype Message type
@@ -466,7 +470,7 @@ function decoder(mtype) {
466
470
  ("case 1:")
467
471
  ("if(u!==%i)", types.mapKey[field.keyType])
468
472
  ("break")
469
- ("k=r.%s()", field.keyType)
473
+ ("k=r.%s()", field.keyType === "string" ? stringMethod(field) : field.keyType)
470
474
  ("continue")
471
475
  ("case 2:")
472
476
  ("if(u!==%i)", types.basic[type] === undefined ? 2 : types.basic[type])
@@ -475,7 +479,7 @@ function decoder(mtype) {
475
479
  if (types.basic[type] === undefined) gen
476
480
  ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
477
481
  else gen
478
- ("v=r.%s()", type);
482
+ ("v=r.%s()", type === "string" ? stringMethod(field) : type);
479
483
 
480
484
  gen
481
485
  ("continue")
@@ -522,7 +526,7 @@ function decoder(mtype) {
522
526
  else gen
523
527
  ("%s.push(types[%i].decode(r,r.uint32(),undefined,q+1))", ref, i);
524
528
  } else gen
525
- ("%s.push(r.%s())", ref, type);
529
+ ("%s.push(r.%s())", ref, type === "string" ? stringMethod(field) : type);
526
530
 
527
531
  // Non-repeated
528
532
  } else if (types.basic[type] === undefined) {
@@ -540,7 +544,7 @@ function decoder(mtype) {
540
544
  ("case %i:{", field.id)
541
545
  ("if(u!==%i)", types.basic[type])
542
546
  ("break")
543
- ("%s=r.%s()", ref, type);
547
+ ("%s=r.%s()", ref, type === "string" ? stringMethod(field) : type);
544
548
  } else {
545
549
  gen
546
550
  ("case %i:{", field.id)
@@ -550,7 +554,9 @@ function decoder(mtype) {
550
554
  // TODO: Protoc rejects open enums whose first value is not zero.
551
555
  // We should do the same, but for v8 this would be a regression.
552
556
  ("if((v=r.%s())!==%j)", type, field.typeDefault);
553
- else if (type === "string" || type === "bytes") gen
557
+ else if (type === "string") gen
558
+ ("if((v=r.%s()).length)", stringMethod(field));
559
+ else if (type === "bytes") gen
554
560
  ("if((v=r.%s()).length)", type);
555
561
  else if (types.long[type] !== undefined) gen
556
562
  ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
@@ -1442,9 +1448,9 @@ Field._configure = function configure(Type_) {
1442
1448
 
1443
1449
  },{"13":13,"23":23,"24":24,"5":5}],7:[function(require,module,exports){
1444
1450
  "use strict";
1445
- var protobuf = module.exports = require(8);
1451
+ exports = module.exports = require(8);
1446
1452
 
1447
- protobuf.build = "light";
1453
+ exports.build = "light";
1448
1454
 
1449
1455
  /**
1450
1456
  * A node-style callback as used by {@link load} and {@link Root#load}.
@@ -1466,9 +1472,9 @@ protobuf.build = "light";
1466
1472
  function load(filename, root, callback) {
1467
1473
  if (typeof root === "function") {
1468
1474
  callback = root;
1469
- root = new protobuf.Root();
1475
+ root = new exports.Root();
1470
1476
  } else if (!root)
1471
- root = new protobuf.Root();
1477
+ root = new exports.Root();
1472
1478
  return root.load(filename, callback);
1473
1479
  }
1474
1480
 
@@ -1496,7 +1502,7 @@ function load(filename, root, callback) {
1496
1502
  */
1497
1503
  // function load(filename:string, [root:Root]):Promise<Root>
1498
1504
 
1499
- protobuf.load = load;
1505
+ exports.load = load;
1500
1506
 
1501
1507
  /**
1502
1508
  * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
@@ -1508,47 +1514,46 @@ protobuf.load = load;
1508
1514
  */
1509
1515
  function loadSync(filename, root) {
1510
1516
  if (!root)
1511
- root = new protobuf.Root();
1517
+ root = new exports.Root();
1512
1518
  return root.loadSync(filename);
1513
1519
  }
1514
1520
 
1515
- protobuf.loadSync = loadSync;
1521
+ exports.loadSync = loadSync;
1516
1522
 
1517
1523
  // Serialization
1518
- protobuf.encoder = require(4);
1519
- protobuf.decoder = require(3);
1520
- protobuf.verifier = require(38);
1521
- protobuf.converter = require(2);
1524
+ exports.encoder = require(4);
1525
+ exports.decoder = require(3);
1526
+ exports.verifier = require(38);
1527
+ exports.converter = require(2);
1522
1528
 
1523
1529
  // Reflection
1524
- protobuf.ReflectionObject = require(13);
1525
- protobuf.Namespace = require(12);
1526
- protobuf.Root = require(17);
1527
- protobuf.Enum = require(5);
1528
- protobuf.Type = require(22);
1529
- protobuf.Field = require(6);
1530
- protobuf.OneOf = require(14);
1531
- protobuf.MapField = require(9);
1532
- protobuf.Service = require(21);
1533
- protobuf.Method = require(11);
1530
+ exports.ReflectionObject = require(13);
1531
+ exports.Namespace = require(12);
1532
+ exports.Root = require(17);
1533
+ exports.Enum = require(5);
1534
+ exports.Type = require(22);
1535
+ exports.Field = require(6);
1536
+ exports.OneOf = require(14);
1537
+ exports.MapField = require(9);
1538
+ exports.Service = require(21);
1539
+ exports.Method = require(11);
1534
1540
 
1535
1541
  // Runtime
1536
- protobuf.Message = require(10);
1537
- protobuf.wrappers = require(39);
1542
+ exports.Message = require(10);
1543
+ exports.wrappers = require(39);
1538
1544
 
1539
1545
  // Utility
1540
- protobuf.types = require(23);
1541
- protobuf.util = require(24);
1546
+ exports.types = require(23);
1547
+ exports.util = require(24);
1542
1548
 
1543
1549
  // Set up possibly cyclic reflection dependencies
1544
- protobuf.ReflectionObject._configure(protobuf.Root);
1545
- protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
1546
- protobuf.Root._configure(protobuf.Type, undefined, {});
1547
- protobuf.Field._configure(protobuf.Type);
1550
+ exports.ReflectionObject._configure(exports.Root);
1551
+ exports.Namespace._configure(exports.Type, exports.Service, exports.Enum);
1552
+ exports.Root._configure(exports.Type, undefined, {});
1553
+ exports.Field._configure(exports.Type);
1548
1554
 
1549
1555
  },{"10":10,"11":11,"12":12,"13":13,"14":14,"17":17,"2":2,"21":21,"22":22,"23":23,"24":24,"3":3,"38":38,"39":39,"4":4,"5":5,"6":6,"8":8,"9":9}],8:[function(require,module,exports){
1550
1556
  "use strict";
1551
- var protobuf = exports;
1552
1557
 
1553
1558
  /**
1554
1559
  * Build type, one of `"full"`, `"light"` or `"minimal"`.
@@ -1556,19 +1561,19 @@ var protobuf = exports;
1556
1561
  * @type {string}
1557
1562
  * @const
1558
1563
  */
1559
- protobuf.build = "minimal";
1564
+ exports.build = "minimal";
1560
1565
 
1561
1566
  // Serialization
1562
- protobuf.Writer = require(40);
1563
- protobuf.BufferWriter = require(41);
1564
- protobuf.Reader = require(15);
1565
- protobuf.BufferReader = require(16);
1567
+ exports.Writer = require(40);
1568
+ exports.BufferWriter = require(41);
1569
+ exports.Reader = require(15);
1570
+ exports.BufferReader = require(16);
1566
1571
 
1567
1572
  // Utility
1568
- protobuf.util = require(33);
1569
- protobuf.rpc = require(19);
1570
- protobuf.roots = require(18);
1571
- protobuf.configure = configure;
1573
+ exports.util = require(33);
1574
+ exports.rpc = require(19);
1575
+ exports.roots = require(18);
1576
+ exports.configure = configure;
1572
1577
 
1573
1578
  /* istanbul ignore next */
1574
1579
  /**
@@ -1576,9 +1581,9 @@ protobuf.configure = configure;
1576
1581
  * @returns {undefined}
1577
1582
  */
1578
1583
  function configure() {
1579
- protobuf.util._configure();
1580
- protobuf.Writer._configure(protobuf.BufferWriter);
1581
- protobuf.Reader._configure(protobuf.BufferReader);
1584
+ exports.util._configure();
1585
+ exports.Writer._configure(exports.BufferWriter);
1586
+ exports.Reader._configure(exports.BufferReader);
1582
1587
  }
1583
1588
 
1584
1589
  // Set up buffer utility according to the environment
@@ -1733,7 +1738,7 @@ var util = require(33);
1733
1738
  * @classdesc Abstract runtime message.
1734
1739
  * @constructor
1735
1740
  * @param {Properties<T>} [properties] Properties to set
1736
- * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
1741
+ * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding when enabled
1737
1742
  * @template T extends object = object
1738
1743
  */
1739
1744
  function Message(properties) {
@@ -2362,7 +2367,8 @@ Namespace.prototype.remove = function remove(object) {
2362
2367
  if (object.parent !== this)
2363
2368
  throw Error(object + " is not a member of " + this);
2364
2369
 
2365
- delete this.nested[object.name];
2370
+ if (!util.remove(this.nested, object, object.name))
2371
+ throw Error(object + " is not a member of " + this);
2366
2372
  if (!Object.keys(this.nested).length)
2367
2373
  this.nested = undefined;
2368
2374
 
@@ -3443,18 +3449,16 @@ function readLongVarint() {
3443
3449
  return bits;
3444
3450
  i = 0;
3445
3451
  } else {
3446
- for (; i < 3; ++i) {
3452
+ for (; i < 4; ++i) {
3447
3453
  /* istanbul ignore if */
3448
3454
  if (this.pos >= this.len)
3449
3455
  throw indexOutOfRange(this);
3450
- // 1st..3th
3456
+ // 1st..4th
3451
3457
  bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
3452
3458
  if (this.buf[this.pos++] < 128)
3453
3459
  return bits;
3454
3460
  }
3455
- // 4th
3456
- bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
3457
- return bits;
3461
+ throw indexOutOfRange(this);
3458
3462
  }
3459
3463
  if (this.len - this.pos > 4) { // fast route (hi)
3460
3464
  for (; i < 5; ++i) {
@@ -3648,6 +3652,23 @@ Reader.prototype.string = function read_string() {
3648
3652
  return utf8.read(this.buf, start, end);
3649
3653
  };
3650
3654
 
3655
+ /**
3656
+ * Reads a string preceeded by its byte length as a varint, rejecting invalid UTF8.
3657
+ * @returns {string} Value read
3658
+ */
3659
+ Reader.prototype.stringVerify = function read_string_verify() {
3660
+ var length = this.uint32(),
3661
+ start = this.pos,
3662
+ end = this.pos + length;
3663
+
3664
+ /* istanbul ignore if */
3665
+ if (end > this.len)
3666
+ throw indexOutOfRange(this, length);
3667
+
3668
+ this.pos = end;
3669
+ return utf8.readStrict(this.buf, start, end);
3670
+ };
3671
+
3651
3672
  /**
3652
3673
  * Skips the specified number of bytes if specified, otherwise skips a varint.
3653
3674
  * @param {number} [length] Length if known, otherwise a varint is assumed
@@ -3679,7 +3700,7 @@ Reader.recursionLimit = util.recursionLimit;
3679
3700
  * Whether readers discard unknown fields while decoding.
3680
3701
  * @type {boolean}
3681
3702
  */
3682
- Reader.discardUnknown = false;
3703
+ Reader.discardUnknown = true;
3683
3704
 
3684
3705
  /**
3685
3706
  * Skips the next element of the specified wire type.
@@ -4819,6 +4840,7 @@ Object.defineProperties(Type.prototype, {
4819
4840
  /**
4820
4841
  * The registered constructor, if any registered, otherwise a generic constructor.
4821
4842
  * 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.
4843
+ * When assigning manually, add the type to its parent namespace/root first if fields reference other reflected types, because constructor setup resolves field defaults.
4822
4844
  * @name Type#ctor
4823
4845
  * @type {Constructor<{}>}
4824
4846
  */
@@ -5088,10 +5110,9 @@ Type.prototype.remove = function remove(object) {
5088
5110
  // See Type#add for the reason why extension fields are excluded here.
5089
5111
 
5090
5112
  /* istanbul ignore if */
5091
- if (!this.fields || this.fields[object.name] !== object)
5113
+ if (!util.remove(this.fields, object, object.name))
5092
5114
  throw Error(object + " is not a member of " + this);
5093
5115
 
5094
- delete this.fields[object.name];
5095
5116
  object.parent = null;
5096
5117
  object.onRemove(this);
5097
5118
  return clearCache(this);
@@ -5099,10 +5120,9 @@ Type.prototype.remove = function remove(object) {
5099
5120
  if (object instanceof OneOf) {
5100
5121
 
5101
5122
  /* istanbul ignore if */
5102
- if (!this.oneofs || this.oneofs[object.name] !== object)
5123
+ if (!util.remove(this.oneofs, object, object.name))
5103
5124
  throw Error(object + " is not a member of " + this);
5104
5125
 
5105
- delete this.oneofs[object.name];
5106
5126
  object.parent = null;
5107
5127
  object.onRemove(this);
5108
5128
  return clearCache(this);
@@ -5577,6 +5597,28 @@ util.toObject = function toObject(array) {
5577
5597
  return object;
5578
5598
  };
5579
5599
 
5600
+ /**
5601
+ * Removes the first matching value from an object.
5602
+ * @param {Object.<string,*>|undefined} object Object to remove from
5603
+ * @param {*} value Value to remove
5604
+ * @param {string} [key] Optional key for fast path removal
5605
+ * @returns {boolean} `true` if removed, otherwise `false`
5606
+ */
5607
+ util.remove = function remove(object, value, key) {
5608
+ if (!object)
5609
+ return false;
5610
+ if (key !== undefined && Object.prototype.hasOwnProperty.call(object, key) && object[key] === value) {
5611
+ delete object[key];
5612
+ return true;
5613
+ }
5614
+ for (var names = Object.keys(object), i = 0; i < names.length; ++i)
5615
+ if (object[names[i]] === value) {
5616
+ delete object[names[i]];
5617
+ return true;
5618
+ }
5619
+ return false;
5620
+ };
5621
+
5580
5622
  /**
5581
5623
  * Tests whether the specified name is a reserved word in JS.
5582
5624
  * @param {string} name Name to test
@@ -7358,6 +7400,28 @@ util._configure = function() {
7358
7400
  */
7359
7401
  var path = exports;
7360
7402
 
7403
+ var urlRe = /^[a-zA-Z][a-zA-Z0-9+.-]+:\/\//;
7404
+
7405
+ function normalizeUrl(path) {
7406
+ if (typeof URL === "undefined" || !urlRe.test(path))
7407
+ return null;
7408
+ try {
7409
+ return new URL(path).href;
7410
+ } catch (e) {
7411
+ return null;
7412
+ }
7413
+ }
7414
+
7415
+ function resolveUrl(originPath, includePath) {
7416
+ if (typeof URL === "undefined" || !urlRe.test(originPath) || urlRe.test(includePath))
7417
+ return null;
7418
+ try {
7419
+ return new URL(includePath, originPath).href;
7420
+ } catch (e) {
7421
+ return null;
7422
+ }
7423
+ }
7424
+
7361
7425
  var isAbsolute =
7362
7426
  /**
7363
7427
  * Tests if the specified path is absolute.
@@ -7375,6 +7439,9 @@ var normalize =
7375
7439
  * @returns {string} Normalized path
7376
7440
  */
7377
7441
  path.normalize = function normalize(path) {
7442
+ var normalizedUrl = normalizeUrl(path);
7443
+ if (normalizedUrl)
7444
+ return normalizedUrl;
7378
7445
  var firstTwoCharacters = path.substring(0,2);
7379
7446
  var uncPrefix = "";
7380
7447
  if (firstTwoCharacters === "\\\\") {
@@ -7413,8 +7480,11 @@ path.normalize = function normalize(path) {
7413
7480
  * @returns {string} Path to the include file
7414
7481
  */
7415
7482
  path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
7483
+ var resolvedUrl = resolveUrl(originPath, includePath);
7484
+ if (resolvedUrl)
7485
+ return resolvedUrl;
7416
7486
  if (!alreadyNormalized)
7417
- includePath = normalize(includePath);
7487
+ includePath = normalize(includePath); // path or absolute url
7418
7488
  if (isAbsolute(includePath))
7419
7489
  return includePath;
7420
7490
  if (!alreadyNormalized)
@@ -7490,7 +7560,8 @@ function pool(alloc, slice, size) {
7490
7560
  * @namespace
7491
7561
  */
7492
7562
  var utf8 = exports,
7493
- replacementChar = "\ufffd";
7563
+ replacementChar = "\ufffd",
7564
+ strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
7494
7565
 
7495
7566
  /**
7496
7567
  * Calculates the UTF8 byte length of a string.
@@ -7579,6 +7650,56 @@ utf8.read = function utf8_read_ascii(buffer, start, end) {
7579
7650
  return str;
7580
7651
  };
7581
7652
 
7653
+ function utf8_read_strict(buffer, start, end) {
7654
+ var source = start === 0 && end === buffer.length
7655
+ ? buffer
7656
+ : buffer.subarray
7657
+ ? buffer.subarray(start, end)
7658
+ : buffer.slice(start, end);
7659
+ if (Array.isArray(source))
7660
+ source = Uint8Array.from(source);
7661
+ return strictDecoder.decode(source);
7662
+ }
7663
+
7664
+ /**
7665
+ * Reads UTF8 bytes as a string, rejecting invalid UTF8.
7666
+ * @param {Uint8Array} buffer Source buffer
7667
+ * @param {number} start Source start
7668
+ * @param {number} end Source end
7669
+ * @returns {string} String read
7670
+ */
7671
+ utf8.readStrict = function utf8_read_strict_ascii(buffer, start, end) {
7672
+ if (end - start < 1)
7673
+ return "";
7674
+
7675
+ var str = "",
7676
+ i = start,
7677
+ c1, c2, c3, c4, c5, c6, c7, c8;
7678
+
7679
+ for (; i + 7 < end; i += 8) {
7680
+ c1 = buffer[i];
7681
+ c2 = buffer[i + 1];
7682
+ c3 = buffer[i + 2];
7683
+ c4 = buffer[i + 3];
7684
+ c5 = buffer[i + 4];
7685
+ c6 = buffer[i + 5];
7686
+ c7 = buffer[i + 6];
7687
+ c8 = buffer[i + 7];
7688
+ if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
7689
+ return str + utf8_read_strict(buffer, i, end);
7690
+ str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
7691
+ }
7692
+
7693
+ for (; i < end; ++i) {
7694
+ c1 = buffer[i];
7695
+ if (c1 & 0x80)
7696
+ return str + utf8_read_strict(buffer, i, end);
7697
+ str += String.fromCharCode(c1);
7698
+ }
7699
+
7700
+ return str;
7701
+ };
7702
+
7582
7703
  /**
7583
7704
  * Writes a string as UTF8 bytes.
7584
7705
  * @param {string} string Source string