protobufjs 6.8.8 → 6.9.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 (108) hide show
  1. package/CHANGELOG.md +941 -921
  2. package/LICENSE +39 -39
  3. package/README.md +901 -879
  4. package/cli/LICENSE +33 -33
  5. package/cli/README.md +11 -11
  6. package/cli/index.d.ts +3 -3
  7. package/cli/index.js +3 -3
  8. package/cli/lib/tsd-jsdoc/LICENSE +20 -20
  9. package/cli/lib/tsd-jsdoc/README.md +23 -23
  10. package/cli/lib/tsd-jsdoc/plugin.js +21 -21
  11. package/cli/lib/tsd-jsdoc/publish.js +705 -693
  12. package/cli/lib/tsd-jsdoc.json +18 -18
  13. package/cli/package.json +1 -1
  14. package/cli/package.standalone.json +32 -32
  15. package/cli/pbjs.d.ts +9 -9
  16. package/cli/pbjs.js +329 -329
  17. package/cli/pbts.d.ts +9 -9
  18. package/cli/pbts.js +197 -197
  19. package/cli/targets/json-module.js +38 -38
  20. package/cli/targets/json.js +8 -8
  21. package/cli/targets/proto.js +326 -326
  22. package/cli/targets/proto2.js +10 -10
  23. package/cli/targets/proto3.js +10 -10
  24. package/cli/targets/static-module.js +29 -29
  25. package/cli/targets/static.js +702 -702
  26. package/cli/util.js +183 -183
  27. package/cli/wrappers/amd.js +7 -7
  28. package/cli/wrappers/closure.js +7 -7
  29. package/cli/wrappers/commonjs.js +7 -7
  30. package/cli/wrappers/default.js +15 -15
  31. package/cli/wrappers/es6.js +5 -5
  32. package/dist/README.md +31 -31
  33. package/dist/light/README.md +31 -31
  34. package/dist/light/protobuf.js +6058 -6032
  35. package/dist/light/protobuf.js.map +1 -1
  36. package/dist/light/protobuf.min.js +3 -3
  37. package/dist/light/protobuf.min.js.map +1 -1
  38. package/dist/minimal/README.md +31 -31
  39. package/dist/minimal/protobuf.js +1900 -1877
  40. package/dist/minimal/protobuf.js.map +1 -1
  41. package/dist/minimal/protobuf.min.js +3 -3
  42. package/dist/minimal/protobuf.min.js.map +1 -1
  43. package/dist/protobuf.js +7625 -7596
  44. package/dist/protobuf.js.map +1 -1
  45. package/dist/protobuf.min.js +3 -3
  46. package/dist/protobuf.min.js.map +1 -1
  47. package/ext/debug/README.md +4 -4
  48. package/ext/debug/index.js +71 -71
  49. package/ext/descriptor/README.md +72 -72
  50. package/ext/descriptor/index.js +1052 -1052
  51. package/ext/descriptor/test.js +54 -54
  52. package/google/LICENSE +27 -27
  53. package/google/README.md +1 -1
  54. package/google/api/annotations.proto +10 -10
  55. package/google/protobuf/descriptor.proto +286 -286
  56. package/google/protobuf/source_context.proto +7 -7
  57. package/index.d.ts +6 -6
  58. package/index.js +4 -4
  59. package/light.d.ts +2 -2
  60. package/light.js +3 -3
  61. package/minimal.d.ts +2 -2
  62. package/minimal.js +4 -4
  63. package/package-lock.json +4223 -3171
  64. package/package.json +122 -122
  65. package/scripts/changelog.js +150 -150
  66. package/scripts/postinstall.js +35 -35
  67. package/src/common.js +399 -399
  68. package/src/converter.js +293 -293
  69. package/src/decoder.js +106 -106
  70. package/src/encoder.js +100 -100
  71. package/src/enum.js +181 -181
  72. package/src/field.js +371 -371
  73. package/src/index-light.js +104 -104
  74. package/src/index-minimal.js +36 -36
  75. package/src/index.js +12 -12
  76. package/src/mapfield.js +126 -126
  77. package/src/message.js +138 -138
  78. package/src/method.js +151 -151
  79. package/src/namespace.js +433 -433
  80. package/src/object.js +200 -200
  81. package/src/oneof.js +203 -203
  82. package/src/parse.js +761 -758
  83. package/src/reader.js +411 -405
  84. package/src/reader_buffer.js +51 -44
  85. package/src/root.js +353 -351
  86. package/src/roots.js +18 -18
  87. package/src/rpc/service.js +142 -142
  88. package/src/rpc.js +36 -36
  89. package/src/service.js +167 -167
  90. package/src/tokenize.js +397 -397
  91. package/src/type.js +589 -589
  92. package/src/types.js +196 -196
  93. package/src/typescript.jsdoc +15 -15
  94. package/src/util/longbits.js +200 -200
  95. package/src/util/minimal.js +414 -414
  96. package/src/util.js +178 -178
  97. package/src/verifier.js +176 -176
  98. package/src/wrappers.js +83 -83
  99. package/src/writer.js +465 -459
  100. package/src/writer_buffer.js +85 -81
  101. package/tsconfig.json +6 -6
  102. package/cli/node_modules/os-tmpdir/index.js +0 -25
  103. package/cli/node_modules/os-tmpdir/license +0 -21
  104. package/cli/node_modules/os-tmpdir/readme.md +0 -32
  105. package/cli/node_modules/tmp/LICENSE +0 -21
  106. package/cli/node_modules/tmp/README.md +0 -314
  107. package/cli/node_modules/tmp/lib/tmp.js +0 -611
  108. package/cli/package-lock.json +0 -20
package/cli/pbts.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- type pbtsCallback = (err: Error|null, output?: string) => void;
2
-
3
- /**
4
- * Runs pbts programmatically.
5
- * @param {string[]} args Command line arguments
6
- * @param {function(?Error, string=)} [callback] Optional completion callback
7
- * @returns {number|undefined} Exit code, if known
8
- */
9
- export function main(args: string[], callback?: pbtsCallback): number|undefined;
1
+ type pbtsCallback = (err: Error|null, output?: string) => void;
2
+
3
+ /**
4
+ * Runs pbts programmatically.
5
+ * @param {string[]} args Command line arguments
6
+ * @param {function(?Error, string=)} [callback] Optional completion callback
7
+ * @returns {number|undefined} Exit code, if known
8
+ */
9
+ export function main(args: string[], callback?: pbtsCallback): number|undefined;
package/cli/pbts.js CHANGED
@@ -1,197 +1,197 @@
1
- "use strict";
2
- var child_process = require("child_process"),
3
- path = require("path"),
4
- fs = require("fs"),
5
- pkg = require("./package.json"),
6
- util = require("./util");
7
-
8
- util.setup();
9
-
10
- var minimist = require("minimist"),
11
- chalk = require("chalk"),
12
- glob = require("glob"),
13
- tmp = require("tmp");
14
-
15
- /**
16
- * Runs pbts programmatically.
17
- * @param {string[]} args Command line arguments
18
- * @param {function(?Error, string=)} [callback] Optional completion callback
19
- * @returns {number|undefined} Exit code, if known
20
- */
21
- exports.main = function(args, callback) {
22
- var argv = minimist(args, {
23
- alias: {
24
- name: "n",
25
- out : "o",
26
- main: "m",
27
- global: "g",
28
- import: "i"
29
- },
30
- string: [ "name", "out", "global", "import" ],
31
- boolean: [ "comments", "main" ],
32
- default: {
33
- comments: true,
34
- main: false
35
- }
36
- });
37
-
38
- var files = argv._;
39
-
40
- if (!files.length) {
41
- if (callback)
42
- callback(Error("usage")); // eslint-disable-line callback-return
43
- else
44
- process.stderr.write([
45
- "protobuf.js v" + pkg.version + " CLI for TypeScript",
46
- "",
47
- chalk.bold.white("Generates TypeScript definitions from annotated JavaScript files."),
48
- "",
49
- " -o, --out Saves to a file instead of writing to stdout.",
50
- "",
51
- " -g, --global Name of the global object in browser environments, if any.",
52
- "",
53
- " -i, --import Comma delimited list of imports. Local names will equal camelCase of the basename.",
54
- "",
55
- " --no-comments Does not output any JSDoc comments.",
56
- "",
57
- chalk.bold.gray(" Internal flags:"),
58
- "",
59
- " -n, --name Wraps everything in a module of the specified name.",
60
- "",
61
- " -m, --main Whether building the main library without any imports.",
62
- "",
63
- "usage: " + chalk.bold.green("pbts") + " [options] file1.js file2.js ..." + chalk.bold.gray(" (or) ") + "other | " + chalk.bold.green("pbts") + " [options] -",
64
- ""
65
- ].join("\n"));
66
- return 1;
67
- }
68
-
69
- // Resolve glob expressions
70
- for (var i = 0; i < files.length;) {
71
- if (glob.hasMagic(files[i])) {
72
- var matches = glob.sync(files[i]);
73
- Array.prototype.splice.apply(files, [i, 1].concat(matches));
74
- i += matches.length;
75
- } else
76
- ++i;
77
- }
78
-
79
- var cleanup = [];
80
-
81
- // Read from stdin (to a temporary file)
82
- if (files.length === 1 && files[0] === "-") {
83
- var data = [];
84
- process.stdin.on("data", function(chunk) {
85
- data.push(chunk);
86
- });
87
- process.stdin.on("end", function() {
88
- files[0] = tmp.tmpNameSync() + ".js";
89
- fs.writeFileSync(files[0], Buffer.concat(data));
90
- cleanup.push(files[0]);
91
- callJsdoc();
92
- });
93
-
94
- // Load from disk
95
- } else {
96
- callJsdoc();
97
- }
98
-
99
- function callJsdoc() {
100
-
101
- // There is no proper API for jsdoc, so this executes the CLI and pipes the output
102
- var basedir = path.join(__dirname, ".");
103
- var moduleName = argv.name || "null";
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(" ");
106
- var child = child_process.exec(cmd, {
107
- cwd: process.cwd(),
108
- argv0: "node",
109
- stdio: "pipe",
110
- maxBuffer: 1 << 24 // 16mb
111
- });
112
- var out = [];
113
- var ended = false;
114
- var closed = false;
115
- child.stdout.on("data", function(data) {
116
- out.push(data);
117
- });
118
- child.stdout.on("end", function() {
119
- if (closed) finish();
120
- else ended = true;
121
- });
122
- child.stderr.pipe(process.stderr);
123
- child.on("close", function(code) {
124
- // clean up temporary files, no matter what
125
- try { cleanup.forEach(fs.unlinkSync); } catch(e) {/**/} cleanup = [];
126
-
127
- if (code) {
128
- out = out.join("").replace(/\s*JSDoc \d+\.\d+\.\d+ [^$]+/, "");
129
- process.stderr.write(out);
130
- var err = Error("code " + code);
131
- if (callback)
132
- return callback(err);
133
- throw err;
134
- }
135
-
136
- if (ended) return finish();
137
- closed = true;
138
- return undefined;
139
- });
140
-
141
- function getImportName(importItem) {
142
- return path.basename(importItem, ".js").replace(/([-_~.+]\w)/g, function(match) {
143
- return match[1].toUpperCase();
144
- });
145
- }
146
-
147
- function finish() {
148
- var output = [];
149
- if (argv.main)
150
- output.push(
151
- "// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.",
152
- ""
153
- );
154
- if (argv.global)
155
- output.push(
156
- "export as namespace " + argv.global + ";",
157
- ""
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
-
178
- output = output.join("\n") + "\n" + out.join("");
179
-
180
- try {
181
- if (argv.out)
182
- fs.writeFileSync(argv.out, output, { encoding: "utf8" });
183
- else if (!callback)
184
- process.stdout.write(output, "utf8");
185
- return callback
186
- ? callback(null, output)
187
- : undefined;
188
- } catch (err) {
189
- if (callback)
190
- return callback(err);
191
- throw err;
192
- }
193
- }
194
- }
195
-
196
- return undefined;
197
- };
1
+ "use strict";
2
+ var child_process = require("child_process"),
3
+ path = require("path"),
4
+ fs = require("fs"),
5
+ pkg = require("./package.json"),
6
+ util = require("./util");
7
+
8
+ util.setup();
9
+
10
+ var minimist = require("minimist"),
11
+ chalk = require("chalk"),
12
+ glob = require("glob"),
13
+ tmp = require("tmp");
14
+
15
+ /**
16
+ * Runs pbts programmatically.
17
+ * @param {string[]} args Command line arguments
18
+ * @param {function(?Error, string=)} [callback] Optional completion callback
19
+ * @returns {number|undefined} Exit code, if known
20
+ */
21
+ exports.main = function(args, callback) {
22
+ var argv = minimist(args, {
23
+ alias: {
24
+ name: "n",
25
+ out : "o",
26
+ main: "m",
27
+ global: "g",
28
+ import: "i"
29
+ },
30
+ string: [ "name", "out", "global", "import" ],
31
+ boolean: [ "comments", "main" ],
32
+ default: {
33
+ comments: true,
34
+ main: false
35
+ }
36
+ });
37
+
38
+ var files = argv._;
39
+
40
+ if (!files.length) {
41
+ if (callback)
42
+ callback(Error("usage")); // eslint-disable-line callback-return
43
+ else
44
+ process.stderr.write([
45
+ "protobuf.js v" + pkg.version + " CLI for TypeScript",
46
+ "",
47
+ chalk.bold.white("Generates TypeScript definitions from annotated JavaScript files."),
48
+ "",
49
+ " -o, --out Saves to a file instead of writing to stdout.",
50
+ "",
51
+ " -g, --global Name of the global object in browser environments, if any.",
52
+ "",
53
+ " -i, --import Comma delimited list of imports. Local names will equal camelCase of the basename.",
54
+ "",
55
+ " --no-comments Does not output any JSDoc comments.",
56
+ "",
57
+ chalk.bold.gray(" Internal flags:"),
58
+ "",
59
+ " -n, --name Wraps everything in a module of the specified name.",
60
+ "",
61
+ " -m, --main Whether building the main library without any imports.",
62
+ "",
63
+ "usage: " + chalk.bold.green("pbts") + " [options] file1.js file2.js ..." + chalk.bold.gray(" (or) ") + "other | " + chalk.bold.green("pbts") + " [options] -",
64
+ ""
65
+ ].join("\n"));
66
+ return 1;
67
+ }
68
+
69
+ // Resolve glob expressions
70
+ for (var i = 0; i < files.length;) {
71
+ if (glob.hasMagic(files[i])) {
72
+ var matches = glob.sync(files[i]);
73
+ Array.prototype.splice.apply(files, [i, 1].concat(matches));
74
+ i += matches.length;
75
+ } else
76
+ ++i;
77
+ }
78
+
79
+ var cleanup = [];
80
+
81
+ // Read from stdin (to a temporary file)
82
+ if (files.length === 1 && files[0] === "-") {
83
+ var data = [];
84
+ process.stdin.on("data", function(chunk) {
85
+ data.push(chunk);
86
+ });
87
+ process.stdin.on("end", function() {
88
+ files[0] = tmp.tmpNameSync() + ".js";
89
+ fs.writeFileSync(files[0], Buffer.concat(data));
90
+ cleanup.push(files[0]);
91
+ callJsdoc();
92
+ });
93
+
94
+ // Load from disk
95
+ } else {
96
+ callJsdoc();
97
+ }
98
+
99
+ function callJsdoc() {
100
+
101
+ // There is no proper API for jsdoc, so this executes the CLI and pipes the output
102
+ var basedir = path.join(__dirname, ".");
103
+ var moduleName = argv.name || "null";
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(" ");
106
+ var child = child_process.exec(cmd, {
107
+ cwd: process.cwd(),
108
+ argv0: "node",
109
+ stdio: "pipe",
110
+ maxBuffer: 1 << 24 // 16mb
111
+ });
112
+ var out = [];
113
+ var ended = false;
114
+ var closed = false;
115
+ child.stdout.on("data", function(data) {
116
+ out.push(data);
117
+ });
118
+ child.stdout.on("end", function() {
119
+ if (closed) finish();
120
+ else ended = true;
121
+ });
122
+ child.stderr.pipe(process.stderr);
123
+ child.on("close", function(code) {
124
+ // clean up temporary files, no matter what
125
+ try { cleanup.forEach(fs.unlinkSync); } catch(e) {/**/} cleanup = [];
126
+
127
+ if (code) {
128
+ out = out.join("").replace(/\s*JSDoc \d+\.\d+\.\d+ [^$]+/, "");
129
+ process.stderr.write(out);
130
+ var err = Error("code " + code);
131
+ if (callback)
132
+ return callback(err);
133
+ throw err;
134
+ }
135
+
136
+ if (ended) return finish();
137
+ closed = true;
138
+ return undefined;
139
+ });
140
+
141
+ function getImportName(importItem) {
142
+ return path.basename(importItem, ".js").replace(/([-_~.+]\w)/g, function(match) {
143
+ return match[1].toUpperCase();
144
+ });
145
+ }
146
+
147
+ function finish() {
148
+ var output = [];
149
+ if (argv.main)
150
+ output.push(
151
+ "// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.",
152
+ ""
153
+ );
154
+ if (argv.global)
155
+ output.push(
156
+ "export as namespace " + argv.global + ";",
157
+ ""
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
+
178
+ output = output.join("\n") + "\n" + out.join("");
179
+
180
+ try {
181
+ if (argv.out)
182
+ fs.writeFileSync(argv.out, output, { encoding: "utf8" });
183
+ else if (!callback)
184
+ process.stdout.write(output, "utf8");
185
+ return callback
186
+ ? callback(null, output)
187
+ : undefined;
188
+ } catch (err) {
189
+ if (callback)
190
+ return callback(err);
191
+ throw err;
192
+ }
193
+ }
194
+ }
195
+
196
+ return undefined;
197
+ };
@@ -1,38 +1,38 @@
1
- "use strict";
2
- module.exports = json_module;
3
-
4
- var util = require("../util");
5
-
6
- var protobuf = require("../..");
7
-
8
- json_module.description = "JSON representation as a module";
9
-
10
- function jsonSafeProp(json) {
11
- return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
12
- return protobuf.util.safeProp($2).charAt(0) === "."
13
- ? $1 + $2 + ":"
14
- : $0;
15
- });
16
- }
17
-
18
- function json_module(root, options, callback) {
19
- try {
20
- var rootProp = protobuf.util.safeProp(options.root || "default");
21
- var output = [
22
- (options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
23
- ];
24
- if (root.options) {
25
- var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
26
- output.push(".setOptions(" + optionsJson + ")\n");
27
- }
28
- var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
29
- output.push(".addJSON(" + json + ");");
30
- output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options));
31
- process.nextTick(function() {
32
- callback(null, output);
33
- });
34
- } catch (e) {
35
- return callback(e);
36
- }
37
- return undefined;
38
- }
1
+ "use strict";
2
+ module.exports = json_module;
3
+
4
+ var util = require("../util");
5
+
6
+ var protobuf = require("../..");
7
+
8
+ json_module.description = "JSON representation as a module";
9
+
10
+ function jsonSafeProp(json) {
11
+ return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
12
+ return protobuf.util.safeProp($2).charAt(0) === "."
13
+ ? $1 + $2 + ":"
14
+ : $0;
15
+ });
16
+ }
17
+
18
+ function json_module(root, options, callback) {
19
+ try {
20
+ var rootProp = protobuf.util.safeProp(options.root || "default");
21
+ var output = [
22
+ (options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
23
+ ];
24
+ if (root.options) {
25
+ var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
26
+ output.push(".setOptions(" + optionsJson + ")\n");
27
+ }
28
+ var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
29
+ output.push(".addJSON(" + json + ");");
30
+ output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options));
31
+ process.nextTick(function() {
32
+ callback(null, output);
33
+ });
34
+ } catch (e) {
35
+ return callback(e);
36
+ }
37
+ return undefined;
38
+ }
@@ -1,8 +1,8 @@
1
- "use strict";
2
- module.exports = json_target;
3
-
4
- json_target.description = "JSON representation";
5
-
6
- function json_target(root, options, callback) {
7
- callback(null, JSON.stringify(root, null, 2));
8
- }
1
+ "use strict";
2
+ module.exports = json_target;
3
+
4
+ json_target.description = "JSON representation";
5
+
6
+ function json_target(root, options, callback) {
7
+ callback(null, JSON.stringify(root, null, 2));
8
+ }