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/src/object.js CHANGED
@@ -194,6 +194,7 @@ ReflectionObject.prototype.toString = function toString() {
194
194
  return className;
195
195
  };
196
196
 
197
+ // Sets up cyclic dependencies (called in index-light)
197
198
  ReflectionObject._configure = function(Root_) {
198
199
  Root = Root_;
199
200
  };
package/src/oneof.js CHANGED
@@ -16,8 +16,9 @@ var Field = require("./field"),
16
16
  * @param {string} name Oneof name
17
17
  * @param {string[]|Object.<string,*>} [fieldNames] Field names
18
18
  * @param {Object.<string,*>} [options] Declared options
19
+ * @param {string} [comment] Comment associated with this field
19
20
  */
20
- function OneOf(name, fieldNames, options) {
21
+ function OneOf(name, fieldNames, options, comment) {
21
22
  if (!Array.isArray(fieldNames)) {
22
23
  options = fieldNames;
23
24
  fieldNames = undefined;
@@ -40,6 +41,12 @@ function OneOf(name, fieldNames, options) {
40
41
  * @readonly
41
42
  */
42
43
  this.fieldsArray = []; // declared readonly for conformance, possibly not yet added to parent
44
+
45
+ /**
46
+ * Comment for this field.
47
+ * @type {string|null}
48
+ */
49
+ this.comment = comment;
43
50
  }
44
51
 
45
52
  /**
@@ -57,17 +64,20 @@ function OneOf(name, fieldNames, options) {
57
64
  * @throws {TypeError} If arguments are invalid
58
65
  */
59
66
  OneOf.fromJSON = function fromJSON(name, json) {
60
- return new OneOf(name, json.oneof, json.options);
67
+ return new OneOf(name, json.oneof, json.options, json.comment);
61
68
  };
62
69
 
63
70
  /**
64
71
  * Converts this oneof to a oneof descriptor.
72
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
65
73
  * @returns {IOneOf} Oneof descriptor
66
74
  */
67
- OneOf.prototype.toJSON = function toJSON() {
75
+ OneOf.prototype.toJSON = function toJSON(toJSONOptions) {
76
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
68
77
  return util.toObject([
69
78
  "options" , this.options,
70
- "oneof" , this.oneof
79
+ "oneof" , this.oneof,
80
+ "comment" , keepComments ? this.comment : undefined
71
81
  ]);
72
82
  };
73
83
 
package/src/parse.js CHANGED
@@ -24,8 +24,8 @@ var base10Re = /^[1-9][0-9]*$/,
24
24
  base8NegRe = /^-?0[0-7]+$/,
25
25
  numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,
26
26
  nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
27
- typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/,
28
- fqTypeRefRe = /^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/;
27
+ typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
28
+ fqTypeRefRe = /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;
29
29
 
30
30
  /**
31
31
  * Result object returned from {@link parse}.
@@ -41,6 +41,13 @@ var base10Re = /^[1-9][0-9]*$/,
41
41
  * Options modifying the behavior of {@link parse}.
42
42
  * @interface IParseOptions
43
43
  * @property {boolean} [keepCase=false] Keeps field casing instead of converting to camel case
44
+ * @property {boolean} [alternateCommentMode=false] Recognize double-slash comments in addition to doc-block comments.
45
+ */
46
+
47
+ /**
48
+ * Options modifying the behavior of JSON serialization.
49
+ * @interface IToJSONOptions
50
+ * @property {boolean} [keepComments=false] Serializes comments.
44
51
  */
45
52
 
46
53
  /**
@@ -61,7 +68,7 @@ function parse(source, root, options) {
61
68
  if (!options)
62
69
  options = parse.defaults;
63
70
 
64
- var tn = tokenize(source),
71
+ var tn = tokenize(source, options.alternateCommentMode || false),
65
72
  next = tn.next,
66
73
  push = tn.push,
67
74
  peek = tn.peek,
@@ -560,6 +567,7 @@ function parse(source, root, options) {
560
567
  else
561
568
  setOption(parent, name + "." + token, readValue(true));
562
569
  }
570
+ skip(",", true);
563
571
  } while (!skip("}", true));
564
572
  } else
565
573
  setOption(parent, name, readValue(true));
package/src/reader.js CHANGED
@@ -360,11 +360,9 @@ Reader.prototype.skipType = function(wireType) {
360
360
  this.skip(this.uint32());
361
361
  break;
362
362
  case 3:
363
- do { // eslint-disable-line no-constant-condition
364
- if ((wireType = this.uint32() & 7) === 4)
365
- break;
363
+ while ((wireType = this.uint32() & 7) !== 4) {
366
364
  this.skipType(wireType);
367
- } while (true);
365
+ }
368
366
  break;
369
367
  case 5:
370
368
  this.skip(4);
package/src/root.js CHANGED
@@ -343,8 +343,9 @@ Root.prototype._handleRemove = function _handleRemove(object) {
343
343
  }
344
344
  };
345
345
 
346
+ // Sets up cyclic dependencies (called in index-light)
346
347
  Root._configure = function(Type_, parse_, common_) {
347
- Type = Type_;
348
- parse = parse_;
348
+ Type = Type_;
349
+ parse = parse_;
349
350
  common = common_;
350
351
  };
package/src/service.js CHANGED
@@ -57,19 +57,23 @@ Service.fromJSON = function fromJSON(name, json) {
57
57
  service.add(Method.fromJSON(names[i], json.methods[names[i]]));
58
58
  if (json.nested)
59
59
  service.addJSON(json.nested);
60
+ service.comment = json.comment;
60
61
  return service;
61
62
  };
62
63
 
63
64
  /**
64
65
  * Converts this service to a service descriptor.
66
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
65
67
  * @returns {IService} Service descriptor
66
68
  */
67
- Service.prototype.toJSON = function toJSON() {
68
- var inherited = Namespace.prototype.toJSON.call(this);
69
+ Service.prototype.toJSON = function toJSON(toJSONOptions) {
70
+ var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
71
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
69
72
  return util.toObject([
70
73
  "options" , inherited && inherited.options || undefined,
71
- "methods" , Namespace.arrayToJSON(this.methodsArray) || /* istanbul ignore next */ {},
72
- "nested" , inherited && inherited.nested || undefined
74
+ "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
75
+ "nested" , inherited && inherited.nested || undefined,
76
+ "comment" , keepComments ? this.comment : undefined
73
77
  ]);
74
78
  };
75
79
 
package/src/tokenize.js CHANGED
@@ -6,6 +6,7 @@ var delimRe = /[\s{}=;:[\],'"()<>]/g,
6
6
  stringSingleRe = /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g;
7
7
 
8
8
  var setCommentRe = /^ *[*/]+ */,
9
+ setCommentAltRe = /^\s*\*?\/*/,
9
10
  setCommentSplitRe = /\n/g,
10
11
  whitespaceRe = /\s/,
11
12
  unescapeRe = /\\(.?)/g;
@@ -92,9 +93,10 @@ tokenize.unescape = unescape;
92
93
  /**
93
94
  * Tokenizes the given .proto source and returns an object with useful utility functions.
94
95
  * @param {string} source Source contents
96
+ * @param {boolean} alternateCommentMode Whether we should activate alternate comment parsing mode.
95
97
  * @returns {ITokenizerHandle} Tokenizer handle
96
98
  */
97
- function tokenize(source) {
99
+ function tokenize(source, alternateCommentMode) {
98
100
  /* eslint-disable callback-return */
99
101
  source = source.toString();
100
102
 
@@ -159,10 +161,17 @@ function tokenize(source) {
159
161
  commentType = source.charAt(start++);
160
162
  commentLine = line;
161
163
  commentLineEmpty = false;
162
- var offset = start - 3, // "///" or "/**"
164
+ var lookback;
165
+ if (alternateCommentMode) {
166
+ lookback = 2; // alternate comment parsing: "//" or "/*"
167
+ } else {
168
+ lookback = 3; // "///" or "/**"
169
+ }
170
+ var commentOffset = start - lookback,
163
171
  c;
164
172
  do {
165
- if (--offset < 0 || (c = source.charAt(offset)) === "\n") {
173
+ if (--commentOffset < 0 ||
174
+ (c = source.charAt(commentOffset)) === "\n") {
166
175
  commentLineEmpty = true;
167
176
  break;
168
177
  }
@@ -171,12 +180,34 @@ function tokenize(source) {
171
180
  .substring(start, end)
172
181
  .split(setCommentSplitRe);
173
182
  for (var i = 0; i < lines.length; ++i)
174
- lines[i] = lines[i].replace(setCommentRe, "").trim();
183
+ lines[i] = lines[i]
184
+ .replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")
185
+ .trim();
175
186
  commentText = lines
176
187
  .join("\n")
177
188
  .trim();
178
189
  }
179
190
 
191
+ function isDoubleSlashCommentLine(startOffset) {
192
+ var endOffset = findEndOfLine(startOffset);
193
+
194
+ // see if remaining line matches comment pattern
195
+ var lineText = source.substring(startOffset, endOffset);
196
+ // look for 1 or 2 slashes since startOffset would already point past
197
+ // the first slash that started the comment.
198
+ var isComment = /^\s*\/{1,2}/.test(lineText);
199
+ return isComment;
200
+ }
201
+
202
+ function findEndOfLine(cursor) {
203
+ // find end of cursor's line
204
+ var endOffset = cursor;
205
+ while (endOffset < length && charAt(endOffset) !== "\n") {
206
+ endOffset++;
207
+ }
208
+ return endOffset;
209
+ }
210
+
180
211
  /**
181
212
  * Obtains the next token.
182
213
  * @returns {string|null} Next token or `null` on eof
@@ -202,35 +233,71 @@ function tokenize(source) {
202
233
  if (++offset === length)
203
234
  return null;
204
235
  }
236
+
205
237
  if (charAt(offset) === "/") {
206
- if (++offset === length)
238
+ if (++offset === length) {
207
239
  throw illegal("comment");
240
+ }
208
241
  if (charAt(offset) === "/") { // Line
209
- isDoc = charAt(start = offset + 1) === "/";
210
- while (charAt(++offset) !== "\n")
211
- if (offset === length)
212
- return null;
213
- ++offset;
214
- if (isDoc) /// Comment
215
- setComment(start, offset - 1);
216
- ++line;
217
- repeat = true;
242
+ if (!alternateCommentMode) {
243
+ // check for triple-slash comment
244
+ isDoc = charAt(start = offset + 1) === "/";
245
+
246
+ while (charAt(++offset) !== "\n") {
247
+ if (offset === length) {
248
+ return null;
249
+ }
250
+ }
251
+ ++offset;
252
+ if (isDoc) {
253
+ setComment(start, offset - 1);
254
+ }
255
+ ++line;
256
+ repeat = true;
257
+ } else {
258
+ // check for double-slash comments, consolidating consecutive lines
259
+ start = offset;
260
+ isDoc = false;
261
+ if (isDoubleSlashCommentLine(offset)) {
262
+ isDoc = true;
263
+ do {
264
+ offset = findEndOfLine(offset);
265
+ if (offset === length) {
266
+ break;
267
+ }
268
+ offset++;
269
+ } while (isDoubleSlashCommentLine(offset));
270
+ } else {
271
+ offset = Math.min(length, findEndOfLine(offset) + 1);
272
+ }
273
+ if (isDoc) {
274
+ setComment(start, offset);
275
+ }
276
+ line++;
277
+ repeat = true;
278
+ }
218
279
  } else if ((curr = charAt(offset)) === "*") { /* Block */
219
- isDoc = charAt(start = offset + 1) === "*";
280
+ // check for /** (regular comment mode) or /* (alternate comment mode)
281
+ start = offset + 1;
282
+ isDoc = alternateCommentMode || charAt(start) === "*";
220
283
  do {
221
- if (curr === "\n")
284
+ if (curr === "\n") {
222
285
  ++line;
223
- if (++offset === length)
286
+ }
287
+ if (++offset === length) {
224
288
  throw illegal("comment");
289
+ }
225
290
  prev = curr;
226
291
  curr = charAt(offset);
227
292
  } while (prev !== "*" || curr !== "/");
228
293
  ++offset;
229
- if (isDoc) /** Comment */
294
+ if (isDoc) {
230
295
  setComment(start, offset - 2);
296
+ }
231
297
  repeat = true;
232
- } else
298
+ } else {
233
299
  return "/";
300
+ }
234
301
  }
235
302
  } while (repeat);
236
303
 
@@ -302,14 +369,17 @@ function tokenize(source) {
302
369
  function cmnt(trailingLine) {
303
370
  var ret = null;
304
371
  if (trailingLine === undefined) {
305
- if (commentLine === line - 1 && (commentType === "*" || commentLineEmpty))
372
+ if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) {
306
373
  ret = commentText;
374
+ }
307
375
  } else {
308
376
  /* istanbul ignore else */
309
- if (commentLine < trailingLine)
377
+ if (commentLine < trailingLine) {
310
378
  peek();
311
- if (commentLine === trailingLine && !commentLineEmpty && commentType === "/")
379
+ }
380
+ if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) {
312
381
  ret = commentText;
382
+ }
313
383
  }
314
384
  return ret;
315
385
  }
package/src/type.js CHANGED
@@ -270,23 +270,28 @@ Type.fromJSON = function fromJSON(name, json) {
270
270
  type.reserved = json.reserved;
271
271
  if (json.group)
272
272
  type.group = true;
273
+ if (json.comment)
274
+ type.comment = json.comment;
273
275
  return type;
274
276
  };
275
277
 
276
278
  /**
277
279
  * Converts this message type to a message type descriptor.
280
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
278
281
  * @returns {IType} Message type descriptor
279
282
  */
280
- Type.prototype.toJSON = function toJSON() {
281
- var inherited = Namespace.prototype.toJSON.call(this);
283
+ Type.prototype.toJSON = function toJSON(toJSONOptions) {
284
+ var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
285
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
282
286
  return util.toObject([
283
287
  "options" , inherited && inherited.options || undefined,
284
- "oneofs" , Namespace.arrayToJSON(this.oneofsArray),
285
- "fields" , Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; })) || {},
288
+ "oneofs" , Namespace.arrayToJSON(this.oneofsArray, toJSONOptions),
289
+ "fields" , Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; }), toJSONOptions) || {},
286
290
  "extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,
287
291
  "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
288
292
  "group" , this.group || undefined,
289
- "nested" , inherited && inherited.nested || undefined
293
+ "nested" , inherited && inherited.nested || undefined,
294
+ "comment" , keepComments ? this.comment : undefined
290
295
  ]);
291
296
  };
292
297
 
@@ -25,6 +25,12 @@ util.pool = require("@protobufjs/pool");
25
25
  // utility to work with the low and high bits of a 64 bit value
26
26
  util.LongBits = require("./longbits");
27
27
 
28
+ // global object reference
29
+ util.global = typeof window !== "undefined" && window
30
+ || typeof global !== "undefined" && global
31
+ || typeof self !== "undefined" && self
32
+ || this; // eslint-disable-line no-invalid-this
33
+
28
34
  /**
29
35
  * An immuable empty array.
30
36
  * @memberof util
@@ -46,7 +52,7 @@ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next *
46
52
  * @type {boolean}
47
53
  * @const
48
54
  */
49
- util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);
55
+ util.isNode = Boolean(util.global.process && util.global.process.versions && util.global.process.versions.node);
50
56
 
51
57
  /**
52
58
  * Tests if the specified value is an integer.
@@ -164,7 +170,9 @@ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore n
164
170
  * Long.js's Long class if available.
165
171
  * @type {Constructor<Long>}
166
172
  */
167
- util.Long = /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");
173
+ util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
174
+ || /* istanbul ignore next */ util.global.Long
175
+ || util.inquire("long");
168
176
 
169
177
  /**
170
178
  * Regular expression used to verify 2 bit (`bool`) map keys.
@@ -383,6 +391,7 @@ util.toJSONOptions = {
383
391
  json: true
384
392
  };
385
393
 
394
+ // Sets up buffer utility according to the environment (called in index-minimal)
386
395
  util._configure = function() {
387
396
  var Buffer = util.Buffer;
388
397
  /* istanbul ignore if */
@@ -1,21 +0,0 @@
1
- {
2
- "nested": {
3
- "google": {
4
- "nested": {
5
- "protobuf": {
6
- "nested": {
7
- "FieldMask": {
8
- "fields": {
9
- "paths": {
10
- "rule": "repeated",
11
- "type": "string",
12
- "id": 1
13
- }
14
- }
15
- }
16
- }
17
- }
18
- }
19
- }
20
- }
21
- }
@@ -1,7 +0,0 @@
1
- syntax = "proto3";
2
-
3
- package google.protobuf;
4
-
5
- message FieldMask {
6
- repeated string paths = 1;
7
- }