protobufjs 6.11.3 → 7.0.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.
Files changed (60) hide show
  1. package/README.md +7 -174
  2. package/dist/light/protobuf.js +40 -16
  3. package/dist/light/protobuf.js.map +1 -1
  4. package/dist/light/protobuf.min.js +3 -3
  5. package/dist/light/protobuf.min.js.map +1 -1
  6. package/dist/minimal/protobuf.js +27 -10
  7. package/dist/minimal/protobuf.js.map +1 -1
  8. package/dist/minimal/protobuf.min.js +3 -3
  9. package/dist/minimal/protobuf.min.js.map +1 -1
  10. package/dist/protobuf.js +109 -46
  11. package/dist/protobuf.js.map +1 -1
  12. package/dist/protobuf.min.js +3 -3
  13. package/dist/protobuf.min.js.map +1 -1
  14. package/index.d.ts +1 -4
  15. package/package.json +9 -28
  16. package/scripts/postinstall.js +0 -3
  17. package/src/converter.js +1 -1
  18. package/src/decoder.js +4 -3
  19. package/src/field.js +6 -3
  20. package/src/namespace.js +1 -2
  21. package/src/parse.js +38 -14
  22. package/src/roots.js +1 -1
  23. package/src/tokenize.js +31 -16
  24. package/src/util/minimal.js +24 -7
  25. package/src/wrappers.js +2 -2
  26. package/CHANGELOG.md +0 -1027
  27. package/bin/pbjs +0 -6
  28. package/bin/pbts +0 -6
  29. package/cli/LICENSE +0 -33
  30. package/cli/README.md +0 -174
  31. package/cli/bin/pbjs +0 -6
  32. package/cli/bin/pbts +0 -6
  33. package/cli/index.d.ts +0 -3
  34. package/cli/index.js +0 -3
  35. package/cli/lib/tsd-jsdoc/LICENSE +0 -21
  36. package/cli/lib/tsd-jsdoc/README.md +0 -23
  37. package/cli/lib/tsd-jsdoc/plugin.js +0 -21
  38. package/cli/lib/tsd-jsdoc/publish.js +0 -705
  39. package/cli/lib/tsd-jsdoc.json +0 -18
  40. package/cli/package.json +0 -8
  41. package/cli/package.standalone.json +0 -32
  42. package/cli/pbjs.d.ts +0 -9
  43. package/cli/pbjs.js +0 -330
  44. package/cli/pbts.d.ts +0 -9
  45. package/cli/pbts.js +0 -197
  46. package/cli/targets/json-module.js +0 -38
  47. package/cli/targets/json.js +0 -8
  48. package/cli/targets/proto.js +0 -326
  49. package/cli/targets/proto2.js +0 -10
  50. package/cli/targets/proto3.js +0 -10
  51. package/cli/targets/static-module.js +0 -29
  52. package/cli/targets/static.js +0 -711
  53. package/cli/util.js +0 -183
  54. package/cli/wrappers/amd.js +0 -7
  55. package/cli/wrappers/closure.js +0 -7
  56. package/cli/wrappers/commonjs.js +0 -7
  57. package/cli/wrappers/default.js +0 -15
  58. package/cli/wrappers/es6.js +0 -5
  59. package/package-lock.json +0 -7870
  60. package/scripts/changelog.js +0 -150
package/index.d.ts CHANGED
@@ -300,9 +300,6 @@ export class FieldBase extends ReflectionObject {
300
300
  */
301
301
  constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
302
302
 
303
- /** Field rule, if any. */
304
- public rule?: string;
305
-
306
303
  /** Field type. */
307
304
  public type: string;
308
305
 
@@ -1312,7 +1309,7 @@ export class Root extends NamespaceBase {
1312
1309
  /**
1313
1310
  * Named roots.
1314
1311
  * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
1315
- * Can also be used manually to make roots available accross modules.
1312
+ * Can also be used manually to make roots available across modules.
1316
1313
  */
1317
1314
  export let roots: { [k: string]: Root };
1318
1315
 
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "6.11.3",
3
+ "version": "7.0.0",
4
4
  "versionScheme": "~",
5
5
  "description": "Protocol Buffers for JavaScript (& TypeScript).",
6
6
  "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
7
7
  "license": "BSD-3-Clause",
8
8
  "repository": "protobufjs/protobuf.js",
9
- "bugs": "https://github.com/dcodeIO/protobuf.js/issues",
9
+ "bugs": "https://github.com/protobufjs/protobuf.js/issues",
10
10
  "homepage": "https://protobufjs.github.io/protobuf.js/",
11
+ "engines": {
12
+ "node": ">=12.0.0"
13
+ },
11
14
  "keywords": [
12
15
  "protobuf",
13
16
  "protocol-buffers",
@@ -16,15 +19,11 @@
16
19
  ],
17
20
  "main": "index.js",
18
21
  "types": "index.d.ts",
19
- "bin": {
20
- "pbjs": "bin/pbjs",
21
- "pbts": "bin/pbts"
22
- },
23
22
  "scripts": {
24
23
  "bench": "node bench",
25
24
  "build": "npm run build:bundle && npm run build:types",
26
25
  "build:bundle": "gulp --gulpfile scripts/gulpfile.js",
27
- "build:types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js",
26
+ "build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js",
28
27
  "changelog": "node scripts/changelog -w",
29
28
  "coverage": "nyc tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
30
29
  "docs": "jsdoc -c config/jsdoc.json -R README.md --verbose --pedantic",
@@ -32,7 +31,6 @@
32
31
  "lint:sources": "eslint \"**/*.js\" -c config/eslint.json",
33
32
  "lint:types": "tslint \"**/*.d.ts\" -e \"**/node_modules/**\" -t stylish -c config/tslint.json",
34
33
  "pages": "node scripts/pages",
35
- "prepublish": "node scripts/prepublish",
36
34
  "postinstall": "node scripts/postinstall",
37
35
  "prof": "node bench/prof",
38
36
  "test": "npm run test:sources && npm run test:types",
@@ -53,7 +51,7 @@
53
51
  "@protobufjs/utf8": "^1.1.0",
54
52
  "@types/long": "^4.0.1",
55
53
  "@types/node": ">=13.7.0",
56
- "long": "^4.0.0"
54
+ "long": "^5.0.0"
57
55
  },
58
56
  "devDependencies": {
59
57
  "benchmark": "^2.1.4",
@@ -62,27 +60,24 @@
62
60
  "bundle-collapser": "^1.3.0",
63
61
  "chalk": "^4.0.0",
64
62
  "escodegen": "^1.13.0",
65
- "espree": "^7.0.0",
66
63
  "eslint": "^8.15.0",
64
+ "espree": "^7.1.0",
67
65
  "estraverse": "^5.1.0",
68
66
  "gh-pages": "^3.0.0",
69
67
  "git-raw-commits": "^2.0.3",
70
68
  "git-semver-tags": "^4.0.0",
71
- "glob": "^7.1.6",
72
69
  "google-protobuf": "^3.11.3",
73
70
  "gulp": "^4.0.2",
74
71
  "gulp-header": "^2.0.9",
75
72
  "gulp-if": "^3.0.0",
76
- "gulp-sourcemaps": "^2.6.5",
73
+ "gulp-sourcemaps": "^3.0.0",
77
74
  "gulp-uglify": "^3.0.2",
78
75
  "jaguarjs-jsdoc": "github:dcodeIO/jaguarjs-jsdoc",
79
76
  "jsdoc": "^3.6.3",
80
77
  "minimist": "^1.2.0",
81
78
  "nyc": "^15.0.0",
82
79
  "reflect-metadata": "^0.1.13",
83
- "semver": "^7.1.2",
84
80
  "tape": "^5.0.0",
85
- "tmp": "^0.2.0",
86
81
  "tslint": "^6.0.0",
87
82
  "typescript": "^3.7.5",
88
83
  "uglify-js": "^3.7.7",
@@ -90,18 +85,6 @@
90
85
  "vinyl-fs": "^3.0.3",
91
86
  "vinyl-source-stream": "^2.0.0"
92
87
  },
93
- "cliDependencies": [
94
- "semver",
95
- "chalk",
96
- "glob",
97
- "jsdoc",
98
- "minimist",
99
- "tmp",
100
- "uglify-js",
101
- "espree",
102
- "escodegen",
103
- "estraverse"
104
- ],
105
88
  "files": [
106
89
  "index.js",
107
90
  "index.d.ts",
@@ -112,8 +95,6 @@
112
95
  "package-lock.json",
113
96
  "tsconfig.json",
114
97
  "scripts/postinstall.js",
115
- "bin/**",
116
- "cli/**",
117
98
  "dist/**",
118
99
  "ext/**",
119
100
  "google/**",
@@ -4,9 +4,6 @@ var path = require("path"),
4
4
  fs = require("fs"),
5
5
  pkg = require(path.join(__dirname, "..", "package.json"));
6
6
 
7
- // ensure that there is a node_modules folder for cli dependencies
8
- try { fs.mkdirSync(path.join(__dirname, "..", "cli", "node_modules")); } catch (e) {/**/}
9
-
10
7
  // check version scheme used by dependents
11
8
  if (!pkg.versionScheme)
12
9
  return;
package/src/converter.js CHANGED
@@ -71,7 +71,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
71
71
  case "bytes": gen
72
72
  ("if(typeof d%s===\"string\")", prop)
73
73
  ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
74
- ("else if(d%s.length)", prop)
74
+ ("else if(d%s.length >= 0)", prop)
75
75
  ("m%s=d%s", prop, prop);
76
76
  break;
77
77
  case "string": gen
package/src/decoder.js CHANGED
@@ -33,7 +33,7 @@ function decoder(mtype) {
33
33
  var field = mtype._fieldsArray[i].resolve(),
34
34
  type = field.resolvedType instanceof Enum ? "int32" : field.type,
35
35
  ref = "m" + util.safeProp(field.name); gen
36
- ("case %i:", field.id);
36
+ ("case %i: {", field.id);
37
37
 
38
38
  // Map fields
39
39
  if (field.map) { gen
@@ -104,8 +104,9 @@ function decoder(mtype) {
104
104
  else gen
105
105
  ("%s=r.%s()", ref, type);
106
106
  gen
107
- ("break");
108
- // Unknown fields
107
+ ("break")
108
+ ("}");
109
+ // Unknown fields
109
110
  } gen
110
111
  ("default:")
111
112
  ("r.skipType(t&7)")
package/src/field.js CHANGED
@@ -78,13 +78,13 @@ function Field(name, id, type, rule, extend, options, comment) {
78
78
  if (extend !== undefined && !util.isString(extend))
79
79
  throw TypeError("extend must be a string");
80
80
 
81
- if (rule === "proto3_optional") {
82
- rule = "optional";
83
- }
84
81
  /**
85
82
  * Field rule, if any.
86
83
  * @type {string|undefined}
87
84
  */
85
+ if (rule === "proto3_optional") {
86
+ rule = "optional";
87
+ }
88
88
  this.rule = rule && rule !== "optional" ? rule : undefined; // toJSON
89
89
 
90
90
  /**
@@ -270,6 +270,9 @@ Field.prototype.resolve = function resolve() {
270
270
  this.typeDefault = null;
271
271
  else // instanceof Enum
272
272
  this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
273
+ } else if (this.options && this.options.proto3_optional) {
274
+ // proto3 scalar value marked optional; should default to null
275
+ this.typeDefault = null;
273
276
  }
274
277
 
275
278
  // use explicitly set default value if present
package/src/namespace.js CHANGED
@@ -6,7 +6,6 @@ var ReflectionObject = require("./object");
6
6
  ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
7
7
 
8
8
  var Field = require("./field"),
9
- OneOf = require("./oneof"),
10
9
  util = require("./util");
11
10
 
12
11
  var Type, // cyclic
@@ -218,7 +217,7 @@ Namespace.prototype.getEnum = function getEnum(name) {
218
217
  */
219
218
  Namespace.prototype.add = function add(object) {
220
219
 
221
- if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace || object instanceof OneOf))
220
+ if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))
222
221
  throw TypeError("object must be a valid nested object");
223
222
 
224
223
  if (!this.nested)
package/src/parse.js CHANGED
@@ -576,7 +576,7 @@ function parse(source, root, options) {
576
576
  option = name;
577
577
  token = peek();
578
578
  if (fqTypeRefRe.test(token)) {
579
- propName = token.substr(1); //remove '.' before property name
579
+ propName = token.slice(1); //remove '.' before property name
580
580
  name += token;
581
581
  next();
582
582
  }
@@ -587,33 +587,57 @@ function parse(source, root, options) {
587
587
  }
588
588
 
589
589
  function parseOptionValue(parent, name) {
590
- if (skip("{", true)) { // { a: "foo" b { c: "bar" } }
591
- var result = {};
590
+ // { a: "foo" b { c: "bar" } }
591
+ if (skip("{", true)) {
592
+ var objectResult = {};
593
+
592
594
  while (!skip("}", true)) {
593
595
  /* istanbul ignore if */
594
- if (!nameRe.test(token = next()))
596
+ if (!nameRe.test(token = next())) {
595
597
  throw illegal(token, "name");
598
+ }
596
599
 
597
600
  var value;
598
601
  var propName = token;
602
+
603
+ skip(":", true);
604
+
599
605
  if (peek() === "{")
600
606
  value = parseOptionValue(parent, name + "." + token);
601
- else {
602
- skip(":");
603
- if (peek() === "{")
604
- value = parseOptionValue(parent, name + "." + token);
605
- else {
606
- value = readValue(true);
607
- setOption(parent, name + "." + token, value);
607
+ else if (peek() === "[") {
608
+ // option (my_option) = {
609
+ // repeated_value: [ "foo", "bar" ]
610
+ // };
611
+ value = [];
612
+ var lastValue;
613
+ if (skip("[", true)) {
614
+ do {
615
+ lastValue = readValue(true);
616
+ value.push(lastValue);
617
+ } while (skip(",", true));
618
+ skip("]");
619
+ if (typeof lastValue !== "undefined") {
620
+ setOption(parent, name + "." + token, lastValue);
621
+ }
608
622
  }
623
+ } else {
624
+ value = readValue(true);
625
+ setOption(parent, name + "." + token, value);
609
626
  }
610
- var prevValue = result[propName];
627
+
628
+ var prevValue = objectResult[propName];
629
+
611
630
  if (prevValue)
612
631
  value = [].concat(prevValue).concat(value);
613
- result[propName] = value;
632
+
633
+ objectResult[propName] = value;
634
+
635
+ // Semicolons and commas can be optional
614
636
  skip(",", true);
637
+ skip(";", true);
615
638
  }
616
- return result;
639
+
640
+ return objectResult;
617
641
  }
618
642
 
619
643
  var simpleValue = readValue(true);
package/src/roots.js CHANGED
@@ -4,7 +4,7 @@ module.exports = {};
4
4
  /**
5
5
  * Named roots.
6
6
  * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
7
- * Can also be used manually to make roots available accross modules.
7
+ * Can also be used manually to make roots available across modules.
8
8
  * @name roots
9
9
  * @type {Object.<string,Root>}
10
10
  * @example
package/src/tokenize.js CHANGED
@@ -103,11 +103,8 @@ function tokenize(source, alternateCommentMode) {
103
103
  var offset = 0,
104
104
  length = source.length,
105
105
  line = 1,
106
- commentType = null,
107
- commentText = null,
108
- commentLine = 0,
109
- commentLineEmpty = false,
110
- commentIsLeading = false;
106
+ lastCommentLine = 0,
107
+ comments = {};
111
108
 
112
109
  var stack = [];
113
110
 
@@ -160,10 +157,11 @@ function tokenize(source, alternateCommentMode) {
160
157
  * @inner
161
158
  */
162
159
  function setComment(start, end, isLeading) {
163
- commentType = source.charAt(start++);
164
- commentLine = line;
165
- commentLineEmpty = false;
166
- commentIsLeading = isLeading;
160
+ var comment = {
161
+ type: source.charAt(start++),
162
+ lineEmpty: false,
163
+ leading: isLeading,
164
+ };
167
165
  var lookback;
168
166
  if (alternateCommentMode) {
169
167
  lookback = 2; // alternate comment parsing: "//" or "/*"
@@ -175,7 +173,7 @@ function tokenize(source, alternateCommentMode) {
175
173
  do {
176
174
  if (--commentOffset < 0 ||
177
175
  (c = source.charAt(commentOffset)) === "\n") {
178
- commentLineEmpty = true;
176
+ comment.lineEmpty = true;
179
177
  break;
180
178
  }
181
179
  } while (c === " " || c === "\t");
@@ -186,9 +184,12 @@ function tokenize(source, alternateCommentMode) {
186
184
  lines[i] = lines[i]
187
185
  .replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")
188
186
  .trim();
189
- commentText = lines
187
+ comment.text = lines
190
188
  .join("\n")
191
189
  .trim();
190
+
191
+ comments[line] = comment;
192
+ lastCommentLine = line;
192
193
  }
193
194
 
194
195
  function isDoubleSlashCommentLine(startOffset) {
@@ -257,6 +258,9 @@ function tokenize(source, alternateCommentMode) {
257
258
  ++offset;
258
259
  if (isDoc) {
259
260
  setComment(start, offset - 1, isLeadingComment);
261
+ // Trailing comment cannot not be multi-line,
262
+ // so leading comment state should be reset to handle potential next comments
263
+ isLeadingComment = true;
260
264
  }
261
265
  ++line;
262
266
  repeat = true;
@@ -272,12 +276,17 @@ function tokenize(source, alternateCommentMode) {
272
276
  break;
273
277
  }
274
278
  offset++;
279
+ if (!isLeadingComment) {
280
+ // Trailing comment cannot not be multi-line
281
+ break;
282
+ }
275
283
  } while (isDoubleSlashCommentLine(offset));
276
284
  } else {
277
285
  offset = Math.min(length, findEndOfLine(offset) + 1);
278
286
  }
279
287
  if (isDoc) {
280
288
  setComment(start, offset, isLeadingComment);
289
+ isLeadingComment = true;
281
290
  }
282
291
  line++;
283
292
  repeat = true;
@@ -299,6 +308,7 @@ function tokenize(source, alternateCommentMode) {
299
308
  ++offset;
300
309
  if (isDoc) {
301
310
  setComment(start, offset - 2, isLeadingComment);
311
+ isLeadingComment = true;
302
312
  }
303
313
  repeat = true;
304
314
  } else {
@@ -374,17 +384,22 @@ function tokenize(source, alternateCommentMode) {
374
384
  */
375
385
  function cmnt(trailingLine) {
376
386
  var ret = null;
387
+ var comment;
377
388
  if (trailingLine === undefined) {
378
- if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) {
379
- ret = commentIsLeading ? commentText : null;
389
+ comment = comments[line - 1];
390
+ delete comments[line - 1];
391
+ if (comment && (alternateCommentMode || comment.type === "*" || comment.lineEmpty)) {
392
+ ret = comment.leading ? comment.text : null;
380
393
  }
381
394
  } else {
382
395
  /* istanbul ignore else */
383
- if (commentLine < trailingLine) {
396
+ if (lastCommentLine < trailingLine) {
384
397
  peek();
385
398
  }
386
- if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) {
387
- ret = commentIsLeading ? null : commentText;
399
+ comment = comments[trailingLine];
400
+ delete comments[trailingLine];
401
+ if (comment && !comment.lineEmpty && (alternateCommentMode || comment.type === "/")) {
402
+ ret = comment.leading ? null : comment.text;
388
403
  }
389
404
  }
390
405
  return ret;
@@ -280,13 +280,30 @@ function newError(name) {
280
280
  merge(this, properties);
281
281
  }
282
282
 
283
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
284
-
285
- Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
286
-
287
- CustomError.prototype.toString = function toString() {
288
- return this.name + ": " + this.message;
289
- };
283
+ CustomError.prototype = Object.create(Error.prototype, {
284
+ constructor: {
285
+ value: CustomError,
286
+ writable: true,
287
+ enumerable: false,
288
+ configurable: true,
289
+ },
290
+ name: {
291
+ get() { return name; },
292
+ set: undefined,
293
+ enumerable: false,
294
+ // configurable: false would accurately preserve the behavior of
295
+ // the original, but I'm guessing that was not intentional.
296
+ // For an actual error subclass, this property would
297
+ // be configurable.
298
+ configurable: true,
299
+ },
300
+ toString: {
301
+ value() { return this.name + ": " + this.message; },
302
+ writable: true,
303
+ enumerable: false,
304
+ configurable: true,
305
+ },
306
+ });
290
307
 
291
308
  return CustomError;
292
309
  }
package/src/wrappers.js CHANGED
@@ -49,7 +49,7 @@ wrappers[".google.protobuf.Any"] = {
49
49
  if (type) {
50
50
  // type_url does not accept leading "."
51
51
  var type_url = object["@type"].charAt(0) === "." ?
52
- object["@type"].substr(1) : object["@type"];
52
+ object["@type"].slice(1) : object["@type"];
53
53
  // type_url prefix is optional, but path seperator is required
54
54
  if (type_url.indexOf("/") === -1) {
55
55
  type_url = "/" + type_url;
@@ -87,7 +87,7 @@ wrappers[".google.protobuf.Any"] = {
87
87
  if (!(message instanceof this.ctor) && message instanceof Message) {
88
88
  var object = message.$type.toObject(message, options);
89
89
  var messageName = message.$type.fullName[0] === "." ?
90
- message.$type.fullName.substr(1) : message.$type.fullName;
90
+ message.$type.fullName.slice(1) : message.$type.fullName;
91
91
  // Default to type.googleapis.com prefix if no prefix is used
92
92
  if (prefix === "") {
93
93
  prefix = googleApi;