protobufjs 6.11.2 → 7.1.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 (259) hide show
  1. package/README.md +7 -174
  2. package/dist/light/protobuf.js +77 -29
  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 +163 -61
  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 +9 -7
  15. package/package.json +14 -33
  16. package/scripts/postinstall.js +0 -3
  17. package/src/converter.js +10 -4
  18. package/src/decoder.js +4 -3
  19. package/src/enum.js +24 -7
  20. package/src/field.js +6 -3
  21. package/src/namespace.js +3 -3
  22. package/src/parse.js +55 -16
  23. package/src/roots.js +1 -1
  24. package/src/tokenize.js +31 -16
  25. package/src/util/minimal.js +24 -7
  26. package/src/util.js +3 -0
  27. package/src/wrappers.js +2 -2
  28. package/tsconfig.json +2 -1
  29. package/CHANGELOG.md +0 -1019
  30. package/bin/pbjs +0 -6
  31. package/bin/pbts +0 -6
  32. package/cli/LICENSE +0 -33
  33. package/cli/README.md +0 -174
  34. package/cli/bin/pbjs +0 -6
  35. package/cli/bin/pbts +0 -6
  36. package/cli/index.d.ts +0 -3
  37. package/cli/index.js +0 -3
  38. package/cli/lib/tsd-jsdoc/LICENSE +0 -21
  39. package/cli/lib/tsd-jsdoc/README.md +0 -23
  40. package/cli/lib/tsd-jsdoc/plugin.js +0 -21
  41. package/cli/lib/tsd-jsdoc/publish.js +0 -705
  42. package/cli/lib/tsd-jsdoc.json +0 -18
  43. package/cli/node_modules/.package-lock.json +0 -256
  44. package/cli/node_modules/acorn/CHANGELOG.md +0 -620
  45. package/cli/node_modules/acorn/LICENSE +0 -21
  46. package/cli/node_modules/acorn/README.md +0 -269
  47. package/cli/node_modules/acorn/bin/acorn +0 -4
  48. package/cli/node_modules/acorn/dist/acorn.d.ts +0 -209
  49. package/cli/node_modules/acorn/dist/acorn.js +0 -5186
  50. package/cli/node_modules/acorn/dist/acorn.js.map +0 -1
  51. package/cli/node_modules/acorn/dist/acorn.mjs +0 -5155
  52. package/cli/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
  53. package/cli/node_modules/acorn/dist/acorn.mjs.map +0 -1
  54. package/cli/node_modules/acorn/dist/bin.js +0 -64
  55. package/cli/node_modules/acorn/package.json +0 -35
  56. package/cli/node_modules/acorn-jsx/LICENSE +0 -19
  57. package/cli/node_modules/acorn-jsx/README.md +0 -40
  58. package/cli/node_modules/acorn-jsx/index.js +0 -488
  59. package/cli/node_modules/acorn-jsx/package.json +0 -27
  60. package/cli/node_modules/acorn-jsx/xhtml.js +0 -255
  61. package/cli/node_modules/balanced-match/.npmignore +0 -5
  62. package/cli/node_modules/balanced-match/LICENSE.md +0 -21
  63. package/cli/node_modules/balanced-match/README.md +0 -91
  64. package/cli/node_modules/balanced-match/index.js +0 -59
  65. package/cli/node_modules/balanced-match/package.json +0 -49
  66. package/cli/node_modules/brace-expansion/LICENSE +0 -21
  67. package/cli/node_modules/brace-expansion/README.md +0 -129
  68. package/cli/node_modules/brace-expansion/index.js +0 -201
  69. package/cli/node_modules/brace-expansion/package.json +0 -47
  70. package/cli/node_modules/concat-map/.travis.yml +0 -4
  71. package/cli/node_modules/concat-map/LICENSE +0 -18
  72. package/cli/node_modules/concat-map/README.markdown +0 -62
  73. package/cli/node_modules/concat-map/example/map.js +0 -6
  74. package/cli/node_modules/concat-map/index.js +0 -13
  75. package/cli/node_modules/concat-map/package.json +0 -43
  76. package/cli/node_modules/concat-map/test/map.js +0 -39
  77. package/cli/node_modules/deep-is/.npmignore +0 -1
  78. package/cli/node_modules/deep-is/.travis.yml +0 -6
  79. package/cli/node_modules/deep-is/LICENSE +0 -22
  80. package/cli/node_modules/deep-is/README.markdown +0 -70
  81. package/cli/node_modules/deep-is/example/cmp.js +0 -11
  82. package/cli/node_modules/deep-is/index.js +0 -102
  83. package/cli/node_modules/deep-is/package.json +0 -61
  84. package/cli/node_modules/deep-is/test/NaN.js +0 -16
  85. package/cli/node_modules/deep-is/test/cmp.js +0 -23
  86. package/cli/node_modules/deep-is/test/neg-vs-pos-0.js +0 -15
  87. package/cli/node_modules/escodegen/LICENSE.BSD +0 -21
  88. package/cli/node_modules/escodegen/README.md +0 -84
  89. package/cli/node_modules/escodegen/bin/escodegen.js +0 -77
  90. package/cli/node_modules/escodegen/bin/esgenerate.js +0 -64
  91. package/cli/node_modules/escodegen/escodegen.js +0 -2647
  92. package/cli/node_modules/escodegen/package.json +0 -62
  93. package/cli/node_modules/eslint-visitor-keys/CHANGELOG.md +0 -25
  94. package/cli/node_modules/eslint-visitor-keys/LICENSE +0 -201
  95. package/cli/node_modules/eslint-visitor-keys/README.md +0 -98
  96. package/cli/node_modules/eslint-visitor-keys/lib/index.js +0 -81
  97. package/cli/node_modules/eslint-visitor-keys/lib/visitor-keys.json +0 -284
  98. package/cli/node_modules/eslint-visitor-keys/package.json +0 -40
  99. package/cli/node_modules/espree/CHANGELOG.md +0 -509
  100. package/cli/node_modules/espree/LICENSE +0 -25
  101. package/cli/node_modules/espree/README.md +0 -233
  102. package/cli/node_modules/espree/espree.js +0 -177
  103. package/cli/node_modules/espree/lib/ast-node-types.js +0 -96
  104. package/cli/node_modules/espree/lib/espree.js +0 -286
  105. package/cli/node_modules/espree/lib/features.js +0 -29
  106. package/cli/node_modules/espree/lib/options.js +0 -106
  107. package/cli/node_modules/espree/lib/token-translator.js +0 -263
  108. package/cli/node_modules/espree/lib/visitor-keys.js +0 -123
  109. package/cli/node_modules/espree/package.json +0 -64
  110. package/cli/node_modules/esprima/ChangeLog +0 -235
  111. package/cli/node_modules/esprima/LICENSE.BSD +0 -21
  112. package/cli/node_modules/esprima/README.md +0 -46
  113. package/cli/node_modules/esprima/bin/esparse.js +0 -139
  114. package/cli/node_modules/esprima/bin/esvalidate.js +0 -236
  115. package/cli/node_modules/esprima/dist/esprima.js +0 -6709
  116. package/cli/node_modules/esprima/package.json +0 -112
  117. package/cli/node_modules/estraverse/.jshintrc +0 -16
  118. package/cli/node_modules/estraverse/LICENSE.BSD +0 -19
  119. package/cli/node_modules/estraverse/README.md +0 -153
  120. package/cli/node_modules/estraverse/estraverse.js +0 -801
  121. package/cli/node_modules/estraverse/gulpfile.js +0 -70
  122. package/cli/node_modules/estraverse/package.json +0 -40
  123. package/cli/node_modules/esutils/LICENSE.BSD +0 -19
  124. package/cli/node_modules/esutils/README.md +0 -174
  125. package/cli/node_modules/esutils/lib/ast.js +0 -144
  126. package/cli/node_modules/esutils/lib/code.js +0 -135
  127. package/cli/node_modules/esutils/lib/keyword.js +0 -165
  128. package/cli/node_modules/esutils/lib/utils.js +0 -33
  129. package/cli/node_modules/esutils/package.json +0 -44
  130. package/cli/node_modules/fast-levenshtein/LICENSE.md +0 -25
  131. package/cli/node_modules/fast-levenshtein/README.md +0 -104
  132. package/cli/node_modules/fast-levenshtein/levenshtein.js +0 -136
  133. package/cli/node_modules/fast-levenshtein/package.json +0 -39
  134. package/cli/node_modules/fs.realpath/LICENSE +0 -43
  135. package/cli/node_modules/fs.realpath/README.md +0 -33
  136. package/cli/node_modules/fs.realpath/index.js +0 -66
  137. package/cli/node_modules/fs.realpath/old.js +0 -303
  138. package/cli/node_modules/fs.realpath/package.json +0 -26
  139. package/cli/node_modules/glob/LICENSE +0 -21
  140. package/cli/node_modules/glob/README.md +0 -375
  141. package/cli/node_modules/glob/changelog.md +0 -67
  142. package/cli/node_modules/glob/common.js +0 -240
  143. package/cli/node_modules/glob/glob.js +0 -790
  144. package/cli/node_modules/glob/package.json +0 -46
  145. package/cli/node_modules/glob/sync.js +0 -486
  146. package/cli/node_modules/inflight/LICENSE +0 -15
  147. package/cli/node_modules/inflight/README.md +0 -37
  148. package/cli/node_modules/inflight/inflight.js +0 -54
  149. package/cli/node_modules/inflight/package.json +0 -29
  150. package/cli/node_modules/inherits/LICENSE +0 -16
  151. package/cli/node_modules/inherits/README.md +0 -42
  152. package/cli/node_modules/inherits/inherits.js +0 -9
  153. package/cli/node_modules/inherits/inherits_browser.js +0 -27
  154. package/cli/node_modules/inherits/package.json +0 -29
  155. package/cli/node_modules/levn/LICENSE +0 -22
  156. package/cli/node_modules/levn/README.md +0 -196
  157. package/cli/node_modules/levn/lib/cast.js +0 -298
  158. package/cli/node_modules/levn/lib/coerce.js +0 -285
  159. package/cli/node_modules/levn/lib/index.js +0 -22
  160. package/cli/node_modules/levn/lib/parse-string.js +0 -113
  161. package/cli/node_modules/levn/lib/parse.js +0 -102
  162. package/cli/node_modules/levn/package.json +0 -47
  163. package/cli/node_modules/minimatch/LICENSE +0 -15
  164. package/cli/node_modules/minimatch/README.md +0 -209
  165. package/cli/node_modules/minimatch/minimatch.js +0 -923
  166. package/cli/node_modules/minimatch/package.json +0 -30
  167. package/cli/node_modules/once/LICENSE +0 -15
  168. package/cli/node_modules/once/README.md +0 -79
  169. package/cli/node_modules/once/once.js +0 -42
  170. package/cli/node_modules/once/package.json +0 -33
  171. package/cli/node_modules/optionator/CHANGELOG.md +0 -56
  172. package/cli/node_modules/optionator/LICENSE +0 -22
  173. package/cli/node_modules/optionator/README.md +0 -238
  174. package/cli/node_modules/optionator/lib/help.js +0 -260
  175. package/cli/node_modules/optionator/lib/index.js +0 -465
  176. package/cli/node_modules/optionator/lib/util.js +0 -54
  177. package/cli/node_modules/optionator/package.json +0 -44
  178. package/cli/node_modules/path-is-absolute/index.js +0 -20
  179. package/cli/node_modules/path-is-absolute/license +0 -21
  180. package/cli/node_modules/path-is-absolute/package.json +0 -43
  181. package/cli/node_modules/path-is-absolute/readme.md +0 -59
  182. package/cli/node_modules/prelude-ls/CHANGELOG.md +0 -99
  183. package/cli/node_modules/prelude-ls/LICENSE +0 -22
  184. package/cli/node_modules/prelude-ls/README.md +0 -15
  185. package/cli/node_modules/prelude-ls/lib/Func.js +0 -65
  186. package/cli/node_modules/prelude-ls/lib/List.js +0 -686
  187. package/cli/node_modules/prelude-ls/lib/Num.js +0 -130
  188. package/cli/node_modules/prelude-ls/lib/Obj.js +0 -154
  189. package/cli/node_modules/prelude-ls/lib/Str.js +0 -92
  190. package/cli/node_modules/prelude-ls/lib/index.js +0 -178
  191. package/cli/node_modules/prelude-ls/package.json +0 -52
  192. package/cli/node_modules/rimraf/CHANGELOG.md +0 -65
  193. package/cli/node_modules/rimraf/LICENSE +0 -15
  194. package/cli/node_modules/rimraf/README.md +0 -101
  195. package/cli/node_modules/rimraf/bin.js +0 -68
  196. package/cli/node_modules/rimraf/package.json +0 -32
  197. package/cli/node_modules/rimraf/rimraf.js +0 -360
  198. package/cli/node_modules/source-map/CHANGELOG.md +0 -301
  199. package/cli/node_modules/source-map/LICENSE +0 -28
  200. package/cli/node_modules/source-map/README.md +0 -742
  201. package/cli/node_modules/source-map/dist/source-map.debug.js +0 -3234
  202. package/cli/node_modules/source-map/dist/source-map.js +0 -3233
  203. package/cli/node_modules/source-map/dist/source-map.min.js +0 -2
  204. package/cli/node_modules/source-map/dist/source-map.min.js.map +0 -1
  205. package/cli/node_modules/source-map/lib/array-set.js +0 -121
  206. package/cli/node_modules/source-map/lib/base64-vlq.js +0 -140
  207. package/cli/node_modules/source-map/lib/base64.js +0 -67
  208. package/cli/node_modules/source-map/lib/binary-search.js +0 -111
  209. package/cli/node_modules/source-map/lib/mapping-list.js +0 -79
  210. package/cli/node_modules/source-map/lib/quick-sort.js +0 -114
  211. package/cli/node_modules/source-map/lib/source-map-consumer.js +0 -1145
  212. package/cli/node_modules/source-map/lib/source-map-generator.js +0 -425
  213. package/cli/node_modules/source-map/lib/source-node.js +0 -413
  214. package/cli/node_modules/source-map/lib/util.js +0 -488
  215. package/cli/node_modules/source-map/package.json +0 -73
  216. package/cli/node_modules/source-map/source-map.d.ts +0 -98
  217. package/cli/node_modules/source-map/source-map.js +0 -8
  218. package/cli/node_modules/tmp/CHANGELOG.md +0 -288
  219. package/cli/node_modules/tmp/LICENSE +0 -21
  220. package/cli/node_modules/tmp/README.md +0 -365
  221. package/cli/node_modules/tmp/lib/tmp.js +0 -780
  222. package/cli/node_modules/tmp/package.json +0 -58
  223. package/cli/node_modules/type-check/LICENSE +0 -22
  224. package/cli/node_modules/type-check/README.md +0 -210
  225. package/cli/node_modules/type-check/lib/check.js +0 -126
  226. package/cli/node_modules/type-check/lib/index.js +0 -16
  227. package/cli/node_modules/type-check/lib/parse-type.js +0 -196
  228. package/cli/node_modules/type-check/package.json +0 -40
  229. package/cli/node_modules/word-wrap/LICENSE +0 -21
  230. package/cli/node_modules/word-wrap/README.md +0 -182
  231. package/cli/node_modules/word-wrap/index.d.ts +0 -50
  232. package/cli/node_modules/word-wrap/index.js +0 -46
  233. package/cli/node_modules/word-wrap/package.json +0 -77
  234. package/cli/node_modules/wrappy/LICENSE +0 -15
  235. package/cli/node_modules/wrappy/README.md +0 -36
  236. package/cli/node_modules/wrappy/package.json +0 -29
  237. package/cli/node_modules/wrappy/wrappy.js +0 -33
  238. package/cli/package.json +0 -8
  239. package/cli/package.standalone.json +0 -32
  240. package/cli/pbjs.d.ts +0 -9
  241. package/cli/pbjs.js +0 -330
  242. package/cli/pbts.d.ts +0 -9
  243. package/cli/pbts.js +0 -197
  244. package/cli/targets/json-module.js +0 -38
  245. package/cli/targets/json.js +0 -8
  246. package/cli/targets/proto.js +0 -326
  247. package/cli/targets/proto2.js +0 -10
  248. package/cli/targets/proto3.js +0 -10
  249. package/cli/targets/static-module.js +0 -29
  250. package/cli/targets/static.js +0 -711
  251. package/cli/util.js +0 -183
  252. package/cli/wrappers/amd.js +0 -7
  253. package/cli/wrappers/closure.js +0 -7
  254. package/cli/wrappers/commonjs.js +0 -7
  255. package/cli/wrappers/default.js +0 -15
  256. package/cli/wrappers/es6.js +0 -5
  257. package/dist/README.md +0 -31
  258. package/dist/light/README.md +0 -31
  259. package/dist/minimal/README.md +0 -31
package/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v6.11.0 (c) 2016, daniel wirtz
3
- * compiled thu, 29 apr 2021 02:20:44 utc
2
+ * protobuf.js v7.1.0 (c) 2016, daniel wirtz
3
+ * compiled fri, 26 aug 2022 21:49:00 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -1535,8 +1535,14 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1535
1535
  if (field.resolvedType instanceof Enum) { gen
1536
1536
  ("switch(d%s){", prop);
1537
1537
  for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
1538
- if (field.repeated && values[keys[i]] === field.typeDefault) gen
1539
- ("default:");
1538
+ // enum unknown values passthrough
1539
+ if (values[keys[i]] === field.typeDefault) { gen
1540
+ ("default:")
1541
+ ("if(typeof(d%s)===\"number\"){m%s=d%s;break}", prop, prop, prop);
1542
+ if (!field.repeated) gen // fallback to default value only for
1543
+ // arrays, to avoid leaving holes.
1544
+ ("break"); // for non-repeated fields, just ignore
1545
+ }
1540
1546
  gen
1541
1547
  ("case%j:", keys[i])
1542
1548
  ("case %i:", values[keys[i]])
@@ -1583,7 +1589,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1583
1589
  case "bytes": gen
1584
1590
  ("if(typeof d%s===\"string\")", prop)
1585
1591
  ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
1586
- ("else if(d%s.length)", prop)
1592
+ ("else if(d%s.length >= 0)", prop)
1587
1593
  ("m%s=d%s", prop, prop);
1588
1594
  break;
1589
1595
  case "string": gen
@@ -1668,7 +1674,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
1668
1674
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1669
1675
  if (field.resolvedType) {
1670
1676
  if (field.resolvedType instanceof Enum) gen
1671
- ("d%s=o.enums===String?types[%i].values[m%s]:m%s", prop, fieldIndex, prop, prop);
1677
+ ("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
1672
1678
  else gen
1673
1679
  ("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
1674
1680
  } else {
@@ -1840,7 +1846,7 @@ function decoder(mtype) {
1840
1846
  var field = mtype._fieldsArray[i].resolve(),
1841
1847
  type = field.resolvedType instanceof Enum ? "int32" : field.type,
1842
1848
  ref = "m" + util.safeProp(field.name); gen
1843
- ("case %i:", field.id);
1849
+ ("case %i: {", field.id);
1844
1850
 
1845
1851
  // Map fields
1846
1852
  if (field.map) { gen
@@ -1911,8 +1917,9 @@ function decoder(mtype) {
1911
1917
  else gen
1912
1918
  ("%s=r.%s()", ref, type);
1913
1919
  gen
1914
- ("break");
1915
- // Unknown fields
1920
+ ("break")
1921
+ ("}");
1922
+ // Unknown fields
1916
1923
  } gen
1917
1924
  ("default:")
1918
1925
  ("r.skipType(t&7)")
@@ -2057,8 +2064,9 @@ var Namespace = require(23),
2057
2064
  * @param {Object.<string,*>} [options] Declared options
2058
2065
  * @param {string} [comment] The comment for this enum
2059
2066
  * @param {Object.<string,string>} [comments] The value comments for this enum
2067
+ * @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
2060
2068
  */
2061
- function Enum(name, values, options, comment, comments) {
2069
+ function Enum(name, values, options, comment, comments, valuesOptions) {
2062
2070
  ReflectionObject.call(this, name, options);
2063
2071
 
2064
2072
  if (values && typeof values !== "object")
@@ -2088,6 +2096,12 @@ function Enum(name, values, options, comment, comments) {
2088
2096
  */
2089
2097
  this.comments = comments || {};
2090
2098
 
2099
+ /**
2100
+ * Values options, if any
2101
+ * @type {Object<string, Object<string, *>>|undefined}
2102
+ */
2103
+ this.valuesOptions = valuesOptions;
2104
+
2091
2105
  /**
2092
2106
  * Reserved ranges, if any.
2093
2107
  * @type {Array.<number[]|string>}
@@ -2132,11 +2146,12 @@ Enum.fromJSON = function fromJSON(name, json) {
2132
2146
  Enum.prototype.toJSON = function toJSON(toJSONOptions) {
2133
2147
  var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
2134
2148
  return util.toObject([
2135
- "options" , this.options,
2136
- "values" , this.values,
2137
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
2138
- "comment" , keepComments ? this.comment : undefined,
2139
- "comments" , keepComments ? this.comments : undefined
2149
+ "options" , this.options,
2150
+ "valuesOptions" , this.valuesOptions,
2151
+ "values" , this.values,
2152
+ "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
2153
+ "comment" , keepComments ? this.comment : undefined,
2154
+ "comments" , keepComments ? this.comments : undefined
2140
2155
  ]);
2141
2156
  };
2142
2157
 
@@ -2145,11 +2160,12 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
2145
2160
  * @param {string} name Value name
2146
2161
  * @param {number} id Value id
2147
2162
  * @param {string} [comment] Comment, if any
2163
+ * @param {Object.<string, *>|undefined} [options] Options, if any
2148
2164
  * @returns {Enum} `this`
2149
2165
  * @throws {TypeError} If arguments are invalid
2150
2166
  * @throws {Error} If there is already a value with this name or id
2151
2167
  */
2152
- Enum.prototype.add = function add(name, id, comment) {
2168
+ Enum.prototype.add = function add(name, id, comment, options) {
2153
2169
  // utilized by the parser but not by .fromJSON
2154
2170
 
2155
2171
  if (!util.isString(name))
@@ -2174,6 +2190,12 @@ Enum.prototype.add = function add(name, id, comment) {
2174
2190
  } else
2175
2191
  this.valuesById[this.values[name] = id] = name;
2176
2192
 
2193
+ if (options) {
2194
+ if (this.valuesOptions === undefined)
2195
+ this.valuesOptions = {};
2196
+ this.valuesOptions[name] = options || null;
2197
+ }
2198
+
2177
2199
  this.comments[name] = comment || null;
2178
2200
  return this;
2179
2201
  };
@@ -2197,6 +2219,8 @@ Enum.prototype.remove = function remove(name) {
2197
2219
  delete this.valuesById[val];
2198
2220
  delete this.values[name];
2199
2221
  delete this.comments[name];
2222
+ if (this.valuesOptions)
2223
+ delete this.valuesOptions[name];
2200
2224
 
2201
2225
  return this;
2202
2226
  };
@@ -2492,6 +2516,9 @@ Field.prototype.resolve = function resolve() {
2492
2516
  this.typeDefault = null;
2493
2517
  else // instanceof Enum
2494
2518
  this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
2519
+ } else if (this.options && this.options.proto3_optional) {
2520
+ // proto3 scalar value marked optional; should default to null
2521
+ this.typeDefault = null;
2495
2522
  }
2496
2523
 
2497
2524
  // use explicitly set default value if present
@@ -3192,7 +3219,8 @@ var ReflectionObject = require(24);
3192
3219
  ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
3193
3220
 
3194
3221
  var Field = require(16),
3195
- util = require(37);
3222
+ util = require(37),
3223
+ OneOf = require(25);
3196
3224
 
3197
3225
  var Type, // cyclic
3198
3226
  Service,
@@ -3403,7 +3431,7 @@ Namespace.prototype.getEnum = function getEnum(name) {
3403
3431
  */
3404
3432
  Namespace.prototype.add = function add(object) {
3405
3433
 
3406
- if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3434
+ if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3407
3435
  throw TypeError("object must be a valid nested object");
3408
3436
 
3409
3437
  if (!this.nested)
@@ -3618,7 +3646,7 @@ Namespace._configure = function(Type_, Service_, Enum_) {
3618
3646
  Enum = Enum_;
3619
3647
  };
3620
3648
 
3621
- },{"16":16,"24":24,"37":37}],24:[function(require,module,exports){
3649
+ },{"16":16,"24":24,"25":25,"37":37}],24:[function(require,module,exports){
3622
3650
  "use strict";
3623
3651
  module.exports = ReflectionObject;
3624
3652
 
@@ -4514,6 +4542,14 @@ function parse(source, root, options) {
4514
4542
  }
4515
4543
  break;
4516
4544
 
4545
+ case "message":
4546
+ parseType(type, token);
4547
+ break;
4548
+
4549
+ case "enum":
4550
+ parseEnum(type, token);
4551
+ break;
4552
+
4517
4553
  /* istanbul ignore next */
4518
4554
  default:
4519
4555
  throw illegal(token); // there are no groups with proto3 semantics
@@ -4614,7 +4650,14 @@ function parse(source, root, options) {
4614
4650
 
4615
4651
  skip("=");
4616
4652
  var value = parseId(next(), true),
4617
- dummy = {};
4653
+ dummy = {
4654
+ options: undefined
4655
+ };
4656
+ dummy.setOption = function(name, value) {
4657
+ if (this.options === undefined)
4658
+ this.options = {};
4659
+ this.options[name] = value;
4660
+ };
4618
4661
  ifBlock(dummy, function parseEnumValue_block(token) {
4619
4662
 
4620
4663
  /* istanbul ignore else */
@@ -4627,7 +4670,7 @@ function parse(source, root, options) {
4627
4670
  }, function parseEnumValue_line() {
4628
4671
  parseInlineOptions(dummy); // skip
4629
4672
  });
4630
- parent.add(token, value, dummy.comment);
4673
+ parent.add(token, value, dummy.comment, dummy.options);
4631
4674
  }
4632
4675
 
4633
4676
  function parseOption(parent, token) {
@@ -4647,7 +4690,7 @@ function parse(source, root, options) {
4647
4690
  option = name;
4648
4691
  token = peek();
4649
4692
  if (fqTypeRefRe.test(token)) {
4650
- propName = token.substr(1); //remove '.' before property name
4693
+ propName = token.slice(1); //remove '.' before property name
4651
4694
  name += token;
4652
4695
  next();
4653
4696
  }
@@ -4658,33 +4701,57 @@ function parse(source, root, options) {
4658
4701
  }
4659
4702
 
4660
4703
  function parseOptionValue(parent, name) {
4661
- if (skip("{", true)) { // { a: "foo" b { c: "bar" } }
4662
- var result = {};
4704
+ // { a: "foo" b { c: "bar" } }
4705
+ if (skip("{", true)) {
4706
+ var objectResult = {};
4707
+
4663
4708
  while (!skip("}", true)) {
4664
4709
  /* istanbul ignore if */
4665
- if (!nameRe.test(token = next()))
4710
+ if (!nameRe.test(token = next())) {
4666
4711
  throw illegal(token, "name");
4712
+ }
4667
4713
 
4668
4714
  var value;
4669
4715
  var propName = token;
4716
+
4717
+ skip(":", true);
4718
+
4670
4719
  if (peek() === "{")
4671
4720
  value = parseOptionValue(parent, name + "." + token);
4672
- else {
4673
- skip(":");
4674
- if (peek() === "{")
4675
- value = parseOptionValue(parent, name + "." + token);
4676
- else {
4677
- value = readValue(true);
4678
- setOption(parent, name + "." + token, value);
4721
+ else if (peek() === "[") {
4722
+ // option (my_option) = {
4723
+ // repeated_value: [ "foo", "bar" ]
4724
+ // };
4725
+ value = [];
4726
+ var lastValue;
4727
+ if (skip("[", true)) {
4728
+ do {
4729
+ lastValue = readValue(true);
4730
+ value.push(lastValue);
4731
+ } while (skip(",", true));
4732
+ skip("]");
4733
+ if (typeof lastValue !== "undefined") {
4734
+ setOption(parent, name + "." + token, lastValue);
4735
+ }
4679
4736
  }
4737
+ } else {
4738
+ value = readValue(true);
4739
+ setOption(parent, name + "." + token, value);
4680
4740
  }
4681
- var prevValue = result[propName];
4741
+
4742
+ var prevValue = objectResult[propName];
4743
+
4682
4744
  if (prevValue)
4683
4745
  value = [].concat(prevValue).concat(value);
4684
- result[propName] = value;
4746
+
4747
+ objectResult[propName] = value;
4748
+
4749
+ // Semicolons and commas can be optional
4685
4750
  skip(",", true);
4751
+ skip(";", true);
4686
4752
  }
4687
- return result;
4753
+
4754
+ return objectResult;
4688
4755
  }
4689
4756
 
4690
4757
  var simpleValue = readValue(true);
@@ -5728,7 +5795,7 @@ module.exports = {};
5728
5795
  /**
5729
5796
  * Named roots.
5730
5797
  * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
5731
- * Can also be used manually to make roots available accross modules.
5798
+ * Can also be used manually to make roots available across modules.
5732
5799
  * @name roots
5733
5800
  * @type {Object.<string,Root>}
5734
5801
  * @example
@@ -6198,11 +6265,8 @@ function tokenize(source, alternateCommentMode) {
6198
6265
  var offset = 0,
6199
6266
  length = source.length,
6200
6267
  line = 1,
6201
- commentType = null,
6202
- commentText = null,
6203
- commentLine = 0,
6204
- commentLineEmpty = false,
6205
- commentIsLeading = false;
6268
+ lastCommentLine = 0,
6269
+ comments = {};
6206
6270
 
6207
6271
  var stack = [];
6208
6272
 
@@ -6255,10 +6319,11 @@ function tokenize(source, alternateCommentMode) {
6255
6319
  * @inner
6256
6320
  */
6257
6321
  function setComment(start, end, isLeading) {
6258
- commentType = source.charAt(start++);
6259
- commentLine = line;
6260
- commentLineEmpty = false;
6261
- commentIsLeading = isLeading;
6322
+ var comment = {
6323
+ type: source.charAt(start++),
6324
+ lineEmpty: false,
6325
+ leading: isLeading,
6326
+ };
6262
6327
  var lookback;
6263
6328
  if (alternateCommentMode) {
6264
6329
  lookback = 2; // alternate comment parsing: "//" or "/*"
@@ -6270,7 +6335,7 @@ function tokenize(source, alternateCommentMode) {
6270
6335
  do {
6271
6336
  if (--commentOffset < 0 ||
6272
6337
  (c = source.charAt(commentOffset)) === "\n") {
6273
- commentLineEmpty = true;
6338
+ comment.lineEmpty = true;
6274
6339
  break;
6275
6340
  }
6276
6341
  } while (c === " " || c === "\t");
@@ -6281,9 +6346,12 @@ function tokenize(source, alternateCommentMode) {
6281
6346
  lines[i] = lines[i]
6282
6347
  .replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")
6283
6348
  .trim();
6284
- commentText = lines
6349
+ comment.text = lines
6285
6350
  .join("\n")
6286
6351
  .trim();
6352
+
6353
+ comments[line] = comment;
6354
+ lastCommentLine = line;
6287
6355
  }
6288
6356
 
6289
6357
  function isDoubleSlashCommentLine(startOffset) {
@@ -6352,6 +6420,9 @@ function tokenize(source, alternateCommentMode) {
6352
6420
  ++offset;
6353
6421
  if (isDoc) {
6354
6422
  setComment(start, offset - 1, isLeadingComment);
6423
+ // Trailing comment cannot not be multi-line,
6424
+ // so leading comment state should be reset to handle potential next comments
6425
+ isLeadingComment = true;
6355
6426
  }
6356
6427
  ++line;
6357
6428
  repeat = true;
@@ -6367,12 +6438,17 @@ function tokenize(source, alternateCommentMode) {
6367
6438
  break;
6368
6439
  }
6369
6440
  offset++;
6441
+ if (!isLeadingComment) {
6442
+ // Trailing comment cannot not be multi-line
6443
+ break;
6444
+ }
6370
6445
  } while (isDoubleSlashCommentLine(offset));
6371
6446
  } else {
6372
6447
  offset = Math.min(length, findEndOfLine(offset) + 1);
6373
6448
  }
6374
6449
  if (isDoc) {
6375
6450
  setComment(start, offset, isLeadingComment);
6451
+ isLeadingComment = true;
6376
6452
  }
6377
6453
  line++;
6378
6454
  repeat = true;
@@ -6394,6 +6470,7 @@ function tokenize(source, alternateCommentMode) {
6394
6470
  ++offset;
6395
6471
  if (isDoc) {
6396
6472
  setComment(start, offset - 2, isLeadingComment);
6473
+ isLeadingComment = true;
6397
6474
  }
6398
6475
  repeat = true;
6399
6476
  } else {
@@ -6469,17 +6546,22 @@ function tokenize(source, alternateCommentMode) {
6469
6546
  */
6470
6547
  function cmnt(trailingLine) {
6471
6548
  var ret = null;
6549
+ var comment;
6472
6550
  if (trailingLine === undefined) {
6473
- if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) {
6474
- ret = commentIsLeading ? commentText : null;
6551
+ comment = comments[line - 1];
6552
+ delete comments[line - 1];
6553
+ if (comment && (alternateCommentMode || comment.type === "*" || comment.lineEmpty)) {
6554
+ ret = comment.leading ? comment.text : null;
6475
6555
  }
6476
6556
  } else {
6477
6557
  /* istanbul ignore else */
6478
- if (commentLine < trailingLine) {
6558
+ if (lastCommentLine < trailingLine) {
6479
6559
  peek();
6480
6560
  }
6481
- if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) {
6482
- ret = commentIsLeading ? null : commentText;
6561
+ comment = comments[trailingLine];
6562
+ delete comments[trailingLine];
6563
+ if (comment && !comment.lineEmpty && (alternateCommentMode || comment.type === "/")) {
6564
+ ret = comment.leading ? null : comment.text;
6483
6565
  }
6484
6566
  }
6485
6567
  return ret;
@@ -7465,6 +7547,9 @@ util.decorateEnum = function decorateEnum(object) {
7465
7547
  util.setProperty = function setProperty(dst, path, value) {
7466
7548
  function setProp(dst, path, value) {
7467
7549
  var part = path.shift();
7550
+ if (part === "__proto__") {
7551
+ return dst;
7552
+ }
7468
7553
  if (path.length > 0) {
7469
7554
  dst[part] = setProp(dst[part] || {}, path, value);
7470
7555
  } else {
@@ -7982,13 +8067,30 @@ function newError(name) {
7982
8067
  merge(this, properties);
7983
8068
  }
7984
8069
 
7985
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
7986
-
7987
- Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
7988
-
7989
- CustomError.prototype.toString = function toString() {
7990
- return this.name + ": " + this.message;
7991
- };
8070
+ CustomError.prototype = Object.create(Error.prototype, {
8071
+ constructor: {
8072
+ value: CustomError,
8073
+ writable: true,
8074
+ enumerable: false,
8075
+ configurable: true,
8076
+ },
8077
+ name: {
8078
+ get() { return name; },
8079
+ set: undefined,
8080
+ enumerable: false,
8081
+ // configurable: false would accurately preserve the behavior of
8082
+ // the original, but I'm guessing that was not intentional.
8083
+ // For an actual error subclass, this property would
8084
+ // be configurable.
8085
+ configurable: true,
8086
+ },
8087
+ toString: {
8088
+ value() { return this.name + ": " + this.message; },
8089
+ writable: true,
8090
+ enumerable: false,
8091
+ configurable: true,
8092
+ },
8093
+ });
7992
8094
 
7993
8095
  return CustomError;
7994
8096
  }
@@ -8352,7 +8454,7 @@ wrappers[".google.protobuf.Any"] = {
8352
8454
  if (type) {
8353
8455
  // type_url does not accept leading "."
8354
8456
  var type_url = object["@type"].charAt(0) === "." ?
8355
- object["@type"].substr(1) : object["@type"];
8457
+ object["@type"].slice(1) : object["@type"];
8356
8458
  // type_url prefix is optional, but path seperator is required
8357
8459
  if (type_url.indexOf("/") === -1) {
8358
8460
  type_url = "/" + type_url;
@@ -8390,7 +8492,7 @@ wrappers[".google.protobuf.Any"] = {
8390
8492
  if (!(message instanceof this.ctor) && message instanceof Message) {
8391
8493
  var object = message.$type.toObject(message, options);
8392
8494
  var messageName = message.$type.fullName[0] === "." ?
8393
- message.$type.fullName.substr(1) : message.$type.fullName;
8495
+ message.$type.fullName.slice(1) : message.$type.fullName;
8394
8496
  // Default to type.googleapis.com prefix if no prefix is used
8395
8497
  if (prefix === "") {
8396
8498
  prefix = googleApi;