protobufjs 6.8.8 → 6.8.9

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 (104) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +879 -879
  3. package/cli/LICENSE +33 -33
  4. package/cli/README.md +11 -11
  5. package/cli/index.d.ts +3 -3
  6. package/cli/index.js +3 -3
  7. package/cli/lib/tsd-jsdoc/LICENSE +20 -20
  8. package/cli/lib/tsd-jsdoc/README.md +23 -23
  9. package/cli/lib/tsd-jsdoc/plugin.js +21 -21
  10. package/cli/lib/tsd-jsdoc/publish.js +693 -693
  11. package/cli/lib/tsd-jsdoc.json +18 -18
  12. package/cli/package.standalone.json +31 -31
  13. package/cli/pbjs.d.ts +9 -9
  14. package/cli/pbjs.js +329 -329
  15. package/cli/pbts.d.ts +9 -9
  16. package/cli/pbts.js +197 -197
  17. package/cli/targets/json-module.js +38 -38
  18. package/cli/targets/json.js +8 -8
  19. package/cli/targets/proto.js +326 -326
  20. package/cli/targets/proto2.js +10 -10
  21. package/cli/targets/proto3.js +10 -10
  22. package/cli/targets/static-module.js +29 -29
  23. package/cli/targets/static.js +702 -702
  24. package/cli/util.js +183 -183
  25. package/cli/wrappers/amd.js +7 -7
  26. package/cli/wrappers/closure.js +7 -7
  27. package/cli/wrappers/commonjs.js +7 -7
  28. package/cli/wrappers/default.js +15 -15
  29. package/cli/wrappers/es6.js +5 -5
  30. package/dist/README.md +31 -31
  31. package/dist/light/README.md +31 -31
  32. package/dist/light/protobuf.js +6030 -6030
  33. package/dist/light/protobuf.js.map +1 -1
  34. package/dist/light/protobuf.min.js +1 -1
  35. package/dist/light/protobuf.min.js.map +1 -1
  36. package/dist/minimal/README.md +31 -31
  37. package/dist/minimal/protobuf.js +1876 -1876
  38. package/dist/minimal/protobuf.js.map +1 -1
  39. package/dist/minimal/protobuf.min.js +1 -1
  40. package/dist/minimal/protobuf.min.js.map +1 -1
  41. package/dist/protobuf.js +7595 -7595
  42. package/dist/protobuf.js.map +1 -1
  43. package/dist/protobuf.min.js +1 -1
  44. package/dist/protobuf.min.js.map +1 -1
  45. package/ext/debug/README.md +4 -4
  46. package/ext/debug/index.js +71 -71
  47. package/ext/descriptor/README.md +72 -72
  48. package/ext/descriptor/index.js +1052 -1052
  49. package/ext/descriptor/test.js +54 -54
  50. package/google/LICENSE +27 -27
  51. package/google/README.md +1 -1
  52. package/google/api/annotations.proto +10 -10
  53. package/google/protobuf/descriptor.proto +286 -286
  54. package/google/protobuf/source_context.proto +7 -7
  55. package/index.js +4 -4
  56. package/light.d.ts +2 -2
  57. package/light.js +3 -3
  58. package/minimal.d.ts +2 -2
  59. package/minimal.js +4 -4
  60. package/package-lock.json +1748 -642
  61. package/package.json +119 -122
  62. package/scripts/changelog.js +150 -150
  63. package/scripts/postinstall.js +35 -35
  64. package/src/common.js +399 -399
  65. package/src/converter.js +293 -293
  66. package/src/decoder.js +106 -106
  67. package/src/encoder.js +99 -99
  68. package/src/enum.js +181 -181
  69. package/src/field.js +371 -371
  70. package/src/index-light.js +104 -104
  71. package/src/index-minimal.js +36 -36
  72. package/src/index.js +12 -12
  73. package/src/mapfield.js +126 -126
  74. package/src/message.js +138 -138
  75. package/src/method.js +151 -151
  76. package/src/namespace.js +433 -433
  77. package/src/object.js +200 -200
  78. package/src/oneof.js +203 -203
  79. package/src/parse.js +758 -758
  80. package/src/reader.js +405 -405
  81. package/src/reader_buffer.js +44 -44
  82. package/src/root.js +351 -351
  83. package/src/roots.js +18 -18
  84. package/src/rpc/service.js +142 -142
  85. package/src/rpc.js +36 -36
  86. package/src/service.js +167 -167
  87. package/src/tokenize.js +397 -397
  88. package/src/type.js +589 -589
  89. package/src/types.js +196 -196
  90. package/src/typescript.jsdoc +15 -15
  91. package/src/util/longbits.js +200 -200
  92. package/src/util/minimal.js +414 -414
  93. package/src/util.js +178 -178
  94. package/src/verifier.js +176 -176
  95. package/src/wrappers.js +83 -83
  96. package/src/writer.js +459 -459
  97. package/src/writer_buffer.js +81 -81
  98. package/tsconfig.json +6 -6
  99. package/cli/node_modules/os-tmpdir/index.js +0 -25
  100. package/cli/node_modules/os-tmpdir/license +0 -21
  101. package/cli/node_modules/os-tmpdir/readme.md +0 -32
  102. package/cli/node_modules/tmp/LICENSE +0 -21
  103. package/cli/node_modules/tmp/README.md +0 -314
  104. package/cli/node_modules/tmp/lib/tmp.js +0 -611
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
+ }