common.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. "use strict";
  2. module.exports = common;
  3. var commonRe = /\/|\./;
  4. /**
  5. * Provides common type definitions.
  6. * Can also be used to provide additional google types or your own custom types.
  7. * @param {string} name Short name as in `google/protobuf/[name].proto` or full file name
  8. * @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
  9. * @returns {undefined}
  10. * @property {INamespace} google/protobuf/any.proto Any
  11. * @property {INamespace} google/protobuf/duration.proto Duration
  12. * @property {INamespace} google/protobuf/empty.proto Empty
  13. * @property {INamespace} google/protobuf/field_mask.proto FieldMask
  14. * @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
  15. * @property {INamespace} google/protobuf/timestamp.proto Timestamp
  16. * @property {INamespace} google/protobuf/wrappers.proto Wrappers
  17. * @example
  18. * // manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension)
  19. * protobuf.common("descriptor", descriptorJson);
  20. *
  21. * // manually provides a custom definition (uses my.foo namespace)
  22. * protobuf.common("my/foo/bar.proto", myFooBarJson);
  23. */
  24. function common(name, json) {
  25. if (!commonRe.test(name)) {
  26. name = "google/protobuf/" + name + ".proto";
  27. json = { nested: { google: { nested: { protobuf: { nested: json } } } } };
  28. }
  29. common[name] = json;
  30. }
  31. // Not provided because of limited use (feel free to discuss or to provide yourself):
  32. //
  33. // google/protobuf/descriptor.proto
  34. // google/protobuf/source_context.proto
  35. // google/protobuf/type.proto
  36. //
  37. // Stripped and pre-parsed versions of these non-bundled files are instead available as part of
  38. // the repository or package within the google/protobuf directory.
  39. common("any", {
  40. /**
  41. * Properties of a google.protobuf.Any message.
  42. * @interface IAny
  43. * @type {Object}
  44. * @property {string} [typeUrl]
  45. * @property {Uint8Array} [bytes]
  46. * @memberof common
  47. */
  48. Any: {
  49. fields: {
  50. type_url: {
  51. type: "string",
  52. id: 1
  53. },
  54. value: {
  55. type: "bytes",
  56. id: 2
  57. }
  58. }
  59. }
  60. });
  61. var timeType;
  62. common("duration", {
  63. /**
  64. * Properties of a google.protobuf.Duration message.
  65. * @interface IDuration
  66. * @type {Object}
  67. * @property {number|Long} [seconds]
  68. * @property {number} [nanos]
  69. * @memberof common
  70. */
  71. Duration: timeType = {
  72. fields: {
  73. seconds: {
  74. type: "int64",
  75. id: 1
  76. },
  77. nanos: {
  78. type: "int32",
  79. id: 2
  80. }
  81. }
  82. }
  83. });
  84. common("timestamp", {
  85. /**
  86. * Properties of a google.protobuf.Timestamp message.
  87. * @interface ITimestamp
  88. * @type {Object}
  89. * @property {number|Long} [seconds]
  90. * @property {number} [nanos]
  91. * @memberof common
  92. */
  93. Timestamp: timeType
  94. });
  95. common("empty", {
  96. /**
  97. * Properties of a google.protobuf.Empty message.
  98. * @interface IEmpty
  99. * @memberof common
  100. */
  101. Empty: {
  102. fields: {}
  103. }
  104. });
  105. common("struct", {
  106. /**
  107. * Properties of a google.protobuf.Struct message.
  108. * @interface IStruct
  109. * @type {Object}
  110. * @property {Object.<string,IValue>} [fields]
  111. * @memberof common
  112. */
  113. Struct: {
  114. fields: {
  115. fields: {
  116. keyType: "string",
  117. type: "Value",
  118. id: 1
  119. }
  120. }
  121. },
  122. /**
  123. * Properties of a google.protobuf.Value message.
  124. * @interface IValue
  125. * @type {Object}
  126. * @property {string} [kind]
  127. * @property {0} [nullValue]
  128. * @property {number} [numberValue]
  129. * @property {string} [stringValue]
  130. * @property {boolean} [boolValue]
  131. * @property {IStruct} [structValue]
  132. * @property {IListValue} [listValue]
  133. * @memberof common
  134. */
  135. Value: {
  136. oneofs: {
  137. kind: {
  138. oneof: [
  139. "nullValue",
  140. "numberValue",
  141. "stringValue",
  142. "boolValue",
  143. "structValue",
  144. "listValue"
  145. ]
  146. }
  147. },
  148. fields: {
  149. nullValue: {
  150. type: "NullValue",
  151. id: 1
  152. },
  153. numberValue: {
  154. type: "double",
  155. id: 2
  156. },
  157. stringValue: {
  158. type: "string",
  159. id: 3
  160. },
  161. boolValue: {
  162. type: "bool",
  163. id: 4
  164. },
  165. structValue: {
  166. type: "Struct",
  167. id: 5
  168. },
  169. listValue: {
  170. type: "ListValue",
  171. id: 6
  172. }
  173. }
  174. },
  175. NullValue: {
  176. values: {
  177. NULL_VALUE: 0
  178. }
  179. },
  180. /**
  181. * Properties of a google.protobuf.ListValue message.
  182. * @interface IListValue
  183. * @type {Object}
  184. * @property {Array.<IValue>} [values]
  185. * @memberof common
  186. */
  187. ListValue: {
  188. fields: {
  189. values: {
  190. rule: "repeated",
  191. type: "Value",
  192. id: 1
  193. }
  194. }
  195. }
  196. });
  197. common("wrappers", {
  198. /**
  199. * Properties of a google.protobuf.DoubleValue message.
  200. * @interface IDoubleValue
  201. * @type {Object}
  202. * @property {number} [value]
  203. * @memberof common
  204. */
  205. DoubleValue: {
  206. fields: {
  207. value: {
  208. type: "double",
  209. id: 1
  210. }
  211. }
  212. },
  213. /**
  214. * Properties of a google.protobuf.FloatValue message.
  215. * @interface IFloatValue
  216. * @type {Object}
  217. * @property {number} [value]
  218. * @memberof common
  219. */
  220. FloatValue: {
  221. fields: {
  222. value: {
  223. type: "float",
  224. id: 1
  225. }
  226. }
  227. },
  228. /**
  229. * Properties of a google.protobuf.Int64Value message.
  230. * @interface IInt64Value
  231. * @type {Object}
  232. * @property {number|Long} [value]
  233. * @memberof common
  234. */
  235. Int64Value: {
  236. fields: {
  237. value: {
  238. type: "int64",
  239. id: 1
  240. }
  241. }
  242. },
  243. /**
  244. * Properties of a google.protobuf.UInt64Value message.
  245. * @interface IUInt64Value
  246. * @type {Object}
  247. * @property {number|Long} [value]
  248. * @memberof common
  249. */
  250. UInt64Value: {
  251. fields: {
  252. value: {
  253. type: "uint64",
  254. id: 1
  255. }
  256. }
  257. },
  258. /**
  259. * Properties of a google.protobuf.Int32Value message.
  260. * @interface IInt32Value
  261. * @type {Object}
  262. * @property {number} [value]
  263. * @memberof common
  264. */
  265. Int32Value: {
  266. fields: {
  267. value: {
  268. type: "int32",
  269. id: 1
  270. }
  271. }
  272. },
  273. /**
  274. * Properties of a google.protobuf.UInt32Value message.
  275. * @interface IUInt32Value
  276. * @type {Object}
  277. * @property {number} [value]
  278. * @memberof common
  279. */
  280. UInt32Value: {
  281. fields: {
  282. value: {
  283. type: "uint32",
  284. id: 1
  285. }
  286. }
  287. },
  288. /**
  289. * Properties of a google.protobuf.BoolValue message.
  290. * @interface IBoolValue
  291. * @type {Object}
  292. * @property {boolean} [value]
  293. * @memberof common
  294. */
  295. BoolValue: {
  296. fields: {
  297. value: {
  298. type: "bool",
  299. id: 1
  300. }
  301. }
  302. },
  303. /**
  304. * Properties of a google.protobuf.StringValue message.
  305. * @interface IStringValue
  306. * @type {Object}
  307. * @property {string} [value]
  308. * @memberof common
  309. */
  310. StringValue: {
  311. fields: {
  312. value: {
  313. type: "string",
  314. id: 1
  315. }
  316. }
  317. },
  318. /**
  319. * Properties of a google.protobuf.BytesValue message.
  320. * @interface IBytesValue
  321. * @type {Object}
  322. * @property {Uint8Array} [value]
  323. * @memberof common
  324. */
  325. BytesValue: {
  326. fields: {
  327. value: {
  328. type: "bytes",
  329. id: 1
  330. }
  331. }
  332. }
  333. });
  334. common("field_mask", {
  335. /**
  336. * Properties of a google.protobuf.FieldMask message.
  337. * @interface IDoubleValue
  338. * @type {Object}
  339. * @property {number} [value]
  340. * @memberof common
  341. */
  342. FieldMask: {
  343. fields: {
  344. paths: {
  345. rule: "repeated",
  346. type: "string",
  347. id: 1
  348. }
  349. }
  350. }
  351. });
  352. /**
  353. * Gets the root definition of the specified common proto file.
  354. *
  355. * Bundled definitions are:
  356. * - google/protobuf/any.proto
  357. * - google/protobuf/duration.proto
  358. * - google/protobuf/empty.proto
  359. * - google/protobuf/field_mask.proto
  360. * - google/protobuf/struct.proto
  361. * - google/protobuf/timestamp.proto
  362. * - google/protobuf/wrappers.proto
  363. *
  364. * @param {string} file Proto file name
  365. * @returns {INamespace|null} Root definition or `null` if not defined
  366. */
  367. common.get = function get(file) {
  368. return common[file] || null;
  369. };