protobufjs 6.8.4 → 6.8.8

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 (52) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +2 -2
  3. package/cli/node_modules/os-tmpdir/index.js +25 -0
  4. package/cli/node_modules/os-tmpdir/license +21 -0
  5. package/cli/node_modules/os-tmpdir/readme.md +32 -0
  6. package/cli/node_modules/tmp/LICENSE +21 -0
  7. package/cli/node_modules/tmp/README.md +314 -0
  8. package/cli/node_modules/tmp/lib/tmp.js +611 -0
  9. package/cli/pbjs.d.ts +1 -1
  10. package/cli/pbjs.js +11 -1
  11. package/cli/pbts.d.ts +1 -1
  12. package/cli/pbts.js +36 -7
  13. package/cli/targets/proto.js +1 -1
  14. package/cli/targets/static.js +3 -6
  15. package/dist/light/protobuf.js +143 -64
  16. package/dist/light/protobuf.js.map +1 -1
  17. package/dist/light/protobuf.min.js +3 -3
  18. package/dist/light/protobuf.min.js.map +1 -1
  19. package/dist/minimal/protobuf.js +23 -14
  20. package/dist/minimal/protobuf.js.map +1 -1
  21. package/dist/minimal/protobuf.min.js +3 -3
  22. package/dist/minimal/protobuf.min.js.map +1 -1
  23. package/dist/protobuf.js +268 -90
  24. package/dist/protobuf.js.map +1 -1
  25. package/dist/protobuf.min.js +3 -3
  26. package/dist/protobuf.min.js.map +1 -1
  27. package/ext/descriptor/index.d.ts +0 -1
  28. package/ext/descriptor/index.js +3 -0
  29. package/index.d.ts +57 -16
  30. package/package-lock.json +4579 -3191
  31. package/package.json +122 -125
  32. package/src/common.js +22 -1
  33. package/src/converter.js +9 -3
  34. package/src/enum.js +17 -5
  35. package/src/field.js +17 -4
  36. package/src/index-light.js +2 -2
  37. package/src/index-minimal.js +1 -1
  38. package/src/mapfield.js +9 -5
  39. package/src/message.js +1 -1
  40. package/src/method.js +14 -4
  41. package/src/namespace.js +14 -10
  42. package/src/object.js +1 -0
  43. package/src/oneof.js +14 -4
  44. package/src/parse.js +11 -3
  45. package/src/reader.js +2 -4
  46. package/src/root.js +3 -2
  47. package/src/service.js +8 -4
  48. package/src/tokenize.js +92 -22
  49. package/src/type.js +10 -5
  50. package/src/util/minimal.js +11 -2
  51. package/google/protobuf/field_mask.json +0 -21
  52. package/google/protobuf/field_mask.proto +0 -7
package/cli/pbts.js CHANGED
@@ -24,9 +24,10 @@ exports.main = function(args, callback) {
24
24
  name: "n",
25
25
  out : "o",
26
26
  main: "m",
27
- global: "g"
27
+ global: "g",
28
+ import: "i"
28
29
  },
29
- string: [ "name", "out", "global" ],
30
+ string: [ "name", "out", "global", "import" ],
30
31
  boolean: [ "comments", "main" ],
31
32
  default: {
32
33
  comments: true,
@@ -49,6 +50,8 @@ exports.main = function(args, callback) {
49
50
  "",
50
51
  " -g, --global Name of the global object in browser environments, if any.",
51
52
  "",
53
+ " -i, --import Comma delimited list of imports. Local names will equal camelCase of the basename.",
54
+ "",
52
55
  " --no-comments Does not output any JSDoc comments.",
53
56
  "",
54
57
  chalk.bold.gray(" Internal flags:"),
@@ -98,7 +101,8 @@ exports.main = function(args, callback) {
98
101
  // There is no proper API for jsdoc, so this executes the CLI and pipes the output
99
102
  var basedir = path.join(__dirname, ".");
100
103
  var moduleName = argv.name || "null";
101
- var cmd = "node \"" + require.resolve("jsdoc/jsdoc.js") + "\" -c \"" + path.join(basedir, "lib", "tsd-jsdoc.json") + "\" -q \"module=" + encodeURIComponent(moduleName) + "&comments=" + Boolean(argv.comments) + "\" " + files.map(function(file) { return "\"" + file + "\""; }).join(" ");
104
+ var nodePath = process.execPath;
105
+ var cmd = "\"" + nodePath + "\" \"" + require.resolve("jsdoc/jsdoc.js") + "\" -c \"" + path.join(basedir, "lib", "tsd-jsdoc.json") + "\" -q \"module=" + encodeURIComponent(moduleName) + "&comments=" + Boolean(argv.comments) + "\" " + files.map(function(file) { return "\"" + file + "\""; }).join(" ");
102
106
  var child = child_process.exec(cmd, {
103
107
  cwd: process.cwd(),
104
108
  argv0: "node",
@@ -134,18 +138,43 @@ exports.main = function(args, callback) {
134
138
  return undefined;
135
139
  });
136
140
 
141
+ function getImportName(importItem) {
142
+ return path.basename(importItem, ".js").replace(/([-_~.+]\w)/g, function(match) {
143
+ return match[1].toUpperCase();
144
+ });
145
+ }
146
+
137
147
  function finish() {
138
148
  var output = [];
139
- if (argv.global)
149
+ if (argv.main)
140
150
  output.push(
141
- "export as namespace " + argv.global + ";",
151
+ "// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.",
142
152
  ""
143
153
  );
144
- if (!argv.main)
154
+ if (argv.global)
145
155
  output.push(
146
- "import * as $protobuf from \"protobufjs\";",
156
+ "export as namespace " + argv.global + ";",
147
157
  ""
148
158
  );
159
+
160
+ if (!argv.main) {
161
+ // Ensure we have a usable array of imports
162
+ var importArray = typeof argv.import === "string" ? argv.import.split(",") : argv.import || [];
163
+
164
+ // Build an object of imports and paths
165
+ var imports = {
166
+ $protobuf: "protobufjs"
167
+ };
168
+ importArray.forEach(function(importItem) {
169
+ imports[getImportName(importItem)] = importItem;
170
+ });
171
+
172
+ // Write out the imports
173
+ Object.keys(imports).forEach(function(key) {
174
+ output.push("import * as " + key + " from \"" + imports[key] + "\";");
175
+ });
176
+ }
177
+
149
178
  output = output.join("\n") + "\n" + out.join("");
150
179
 
151
180
  try {
@@ -70,7 +70,7 @@ function escape(str) {
70
70
  return str.replace(/[\\"']/g, "\\$&")
71
71
  .replace(/\r/g, "\\r")
72
72
  .replace(/\n/g, "\\n")
73
- .replace(/\u0000/g, "\\0");
73
+ .replace(/\u0000/g, "\\0"); // eslint-disable-line no-control-regex
74
74
  }
75
75
 
76
76
  function value(v) {
@@ -172,12 +172,9 @@ var shortVars = {
172
172
  function beautifyCode(code) {
173
173
  // Add semicolons
174
174
  code = UglifyJS.minify(code, {
175
- fromString: true,
176
175
  compress: false,
177
176
  mangle: false,
178
- output: {
179
- beautify: true
180
- }
177
+ output: { beautify: true }
181
178
  }).code;
182
179
  // Properly beautify
183
180
  var ast = espree.parse(code);
@@ -653,11 +650,11 @@ function buildService(ref, service) {
653
650
  "@returns {undefined}",
654
651
  "@variation 1"
655
652
  ]);
656
- push(escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
653
+ push("Object.defineProperty(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
657
654
  ++indent;
658
655
  push("return this.rpcCall(" + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
659
656
  --indent;
660
- push("};");
657
+ push("}, \"name\", { value: " + JSON.stringify(method.name) + " });");
661
658
  if (config.comments)
662
659
  push("");
663
660
  pushComment([