index.js.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: index.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: index.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * @license
  21. * Copyright 2015, Google Inc.
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions are
  26. * met:
  27. *
  28. * * Redistributions of source code must retain the above copyright
  29. * notice, this list of conditions and the following disclaimer.
  30. * * Redistributions in binary form must reproduce the above
  31. * copyright notice, this list of conditions and the following disclaimer
  32. * in the documentation and/or other materials provided with the
  33. * distribution.
  34. * * Neither the name of Google Inc. nor the names of its
  35. * contributors may be used to endorse or promote products derived from
  36. * this software without specific prior written permission.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  41. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  42. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  44. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  45. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  46. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  48. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. *
  50. */
  51. 'use strict';
  52. var path = require('path');
  53. var fs = require('fs');
  54. var SSL_ROOTS_PATH = path.resolve(__dirname, '..', '..', 'etc', 'roots.pem');
  55. var _ = require('lodash');
  56. var ProtoBuf = require('protobufjs');
  57. var client = require('./src/client.js');
  58. var server = require('./src/server.js');
  59. var common = require('./src/common.js');
  60. var Metadata = require('./src/metadata.js');
  61. var grpc = require('./src/grpc_extension');
  62. var protobuf_js_5_common = require('./src/protobuf_js_5_common');
  63. var protobuf_js_6_common = require('./src/protobuf_js_6_common');
  64. var constants = require('./src/constants.js');
  65. grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii'));
  66. /**
  67. * @namespace grpc
  68. */
  69. /**
  70. * Load a ProtoBuf.js object as a gRPC object.
  71. * @memberof grpc
  72. * @alias grpc.loadObject
  73. * @param {Object} value The ProtoBuf.js reflection object to load
  74. * @param {Object=} options Options to apply to the loaded file
  75. * @param {bool=} [options.binaryAsBase64=false] deserialize bytes values as
  76. * base64 strings instead of Buffers
  77. * @param {bool=} [options.longsAsStrings=true] deserialize long values as
  78. * strings instead of objects
  79. * @param {bool=} [options.enumsAsStrings=true] deserialize enum values as
  80. * strings instead of numbers. Only works with Protobuf.js 6 values.
  81. * @param {bool=} [options.deprecatedArgumentOrder=false] use the beta method
  82. * argument order for client methods, with optional arguments after the
  83. * callback. This option is only a temporary stopgap measure to smooth an
  84. * API breakage. It is deprecated, and new code should not use it.
  85. * @param {(number|string)=} [options.protobufjsVersion='detect'] 5 and 6
  86. * respectively indicate that an object from the corresponding version of
  87. * Protobuf.js is provided in the value argument. If the option is 'detect',
  88. * gRPC wll guess what the version is based on the structure of the value.
  89. * @return {Object&lt;string, *>} The resulting gRPC object.
  90. */
  91. exports.loadObject = function loadObject(value, options) {
  92. options = _.defaults(options, common.defaultGrpcOptions);
  93. options = _.defaults(options, {'protobufjsVersion': 'detect'});
  94. var protobufjsVersion;
  95. if (options.protobufjsVersion === 'detect') {
  96. if (protobuf_js_6_common.isProbablyProtobufJs6(value)) {
  97. protobufjsVersion = 6;
  98. } else if (protobuf_js_5_common.isProbablyProtobufJs5(value)) {
  99. protobufjsVersion = 5;
  100. } else {
  101. var error_message = 'Could not detect ProtoBuf.js version. Please ' +
  102. 'specify the version number with the "protobufjs_version" option';
  103. throw new Error(error_message);
  104. }
  105. } else {
  106. protobufjsVersion = options.protobufjsVersion;
  107. }
  108. switch (protobufjsVersion) {
  109. case 6: return protobuf_js_6_common.loadObject(value, options);
  110. case 5:
  111. return protobuf_js_5_common.loadObject(value, options);
  112. default:
  113. throw new Error('Unrecognized protobufjsVersion', protobufjsVersion);
  114. }
  115. };
  116. var loadObject = exports.loadObject;
  117. /**
  118. * Load a gRPC object from a .proto file.
  119. * @memberof grpc
  120. * @alias grpc.load
  121. * @param {string|{root: string, file: string}} filename The file to load
  122. * @param {string=} format The file format to expect. Must be either 'proto' or
  123. * 'json'. Defaults to 'proto'
  124. * @param {Object=} options Options to apply to the loaded file
  125. * @param {bool=} [options.convertFieldsToCamelCase=false] Load this file with
  126. * field names in camel case instead of their original case
  127. * @param {bool=} [options.binaryAsBase64=false] deserialize bytes values as
  128. * base64 strings instead of Buffers
  129. * @param {bool=} [options.longsAsStrings=true] deserialize long values as
  130. * strings instead of objects
  131. * @param {bool=} [options.deprecatedArgumentOrder=false] use the beta method
  132. * argument order for client methods, with optional arguments after the
  133. * callback. This option is only a temporary stopgap measure to smooth an
  134. * API breakage. It is deprecated, and new code should not use it.
  135. * @return {Object&lt;string, *>} The resulting gRPC object
  136. */
  137. exports.load = function load(filename, format, options) {
  138. options = _.defaults(options, common.defaultGrpcOptions);
  139. options.protobufjsVersion = 5;
  140. if (!format) {
  141. format = 'proto';
  142. }
  143. var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
  144. if(options &amp;&amp; options.hasOwnProperty('convertFieldsToCamelCase')) {
  145. ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
  146. }
  147. var builder;
  148. try {
  149. switch(format) {
  150. case 'proto':
  151. builder = ProtoBuf.loadProtoFile(filename);
  152. break;
  153. case 'json':
  154. builder = ProtoBuf.loadJsonFile(filename);
  155. break;
  156. default:
  157. throw new Error('Unrecognized format "' + format + '"');
  158. }
  159. } finally {
  160. ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
  161. }
  162. return loadObject(builder.ns, options);
  163. };
  164. var log_template = _.template(
  165. '{severity} {timestamp}\t{file}:{line}]\t{message}',
  166. {interpolate: /{([\s\S]+?)}/g});
  167. /**
  168. * Sets the logger function for the gRPC module. For debugging purposes, the C
  169. * core will log synchronously directly to stdout unless this function is
  170. * called. Note: the output format here is intended to be informational, and
  171. * is not guaranteed to stay the same in the future.
  172. * Logs will be directed to logger.error.
  173. * @memberof grpc
  174. * @alias grpc.setLogger
  175. * @param {Console} logger A Console-like object.
  176. */
  177. exports.setLogger = function setLogger(logger) {
  178. common.logger = logger;
  179. grpc.setDefaultLoggerCallback(function(file, line, severity,
  180. message, timestamp) {
  181. logger.error(log_template({
  182. file: path.basename(file),
  183. line: line,
  184. severity: severity,
  185. message: message,
  186. timestamp: timestamp.toISOString()
  187. }));
  188. });
  189. };
  190. /**
  191. * Sets the logger verbosity for gRPC module logging. The options are members
  192. * of the grpc.logVerbosity map.
  193. * @memberof grpc
  194. * @alias grpc.setLogVerbosity
  195. * @param {Number} verbosity The minimum severity to log
  196. */
  197. exports.setLogVerbosity = function setLogVerbosity(verbosity) {
  198. common.logVerbosity = verbosity;
  199. grpc.setLogVerbosity(verbosity);
  200. };
  201. exports.Server = server.Server;
  202. exports.Metadata = Metadata;
  203. exports.status = constants.status;
  204. exports.propagate = constants.propagate;
  205. exports.callError = constants.callError;
  206. exports.writeFlags = constants.writeFlags;
  207. exports.logVerbosity = constants.logVerbosity;
  208. exports.credentials = require('./src/credentials.js');
  209. /**
  210. * ServerCredentials factories
  211. * @constructor ServerCredentials
  212. * @memberof grpc
  213. */
  214. exports.ServerCredentials = grpc.ServerCredentials;
  215. /**
  216. * Create insecure server credentials
  217. * @name grpc.ServerCredentials.createInsecure
  218. * @kind function
  219. * @return grpc.ServerCredentials
  220. */
  221. /**
  222. * A private key and certificate pair
  223. * @typedef {Object} grpc.ServerCredentials~keyCertPair
  224. * @property {Buffer} privateKey The server's private key
  225. * @property {Buffer} certChain The server's certificate chain
  226. */
  227. /**
  228. * Create SSL server credentials
  229. * @name grpc.ServerCredentials.createInsecure
  230. * @kind function
  231. * @param {?Buffer} rootCerts Root CA certificates for validating client
  232. * certificates
  233. * @param {Array&lt;grpc.ServerCredentials~keyCertPair>} keyCertPairs A list of
  234. * private key and certificate chain pairs to be used for authenticating
  235. * the server
  236. * @param {boolean} [checkClientCertificate=false] Indicates that the server
  237. * should request and verify the client's certificates
  238. * @return grpc.ServerCredentials
  239. */
  240. exports.makeGenericClientConstructor = client.makeClientConstructor;
  241. exports.getClientChannel = client.getClientChannel;
  242. exports.waitForClientReady = client.waitForClientReady;
  243. /**
  244. * @memberof grpc
  245. * @alias grpc.closeClient
  246. * @param {grpc.Client} client_obj The client to close
  247. */
  248. exports.closeClient = function closeClient(client_obj) {
  249. client.Client.prototype.close.apply(client_obj);
  250. };
  251. exports.Client = client.Client;
  252. </code></pre>
  253. </article>
  254. </section>
  255. </div>
  256. <nav>
  257. <h2><a href="index.html">Home</a></h2><h3>Externals</h3><ul><li><a href="external-Duplex.html">Duplex</a></li><li><a href="external-EventEmitter.html">EventEmitter</a></li><li><a href="external-GoogleCredential.html">GoogleCredential</a></li><li><a href="external-Readable.html">Readable</a></li><li><a href="external-Writable.html">Writable</a></li></ul><h3>Classes</h3><ul><li><a href="grpc.Client.html">Client</a></li><li><a href="grpc.credentials-CallCredentials.html">CallCredentials</a></li><li><a href="grpc.credentials-ChannelCredentials.html">ChannelCredentials</a></li><li><a href="grpc.Metadata.html">Metadata</a></li><li><a href="grpc.Server.html">Server</a></li><li><a href="grpc.ServerCredentials.html">ServerCredentials</a></li><li><a href="grpc-ClientDuplexStream.html">ClientDuplexStream</a></li><li><a href="grpc-ClientReadableStream.html">ClientReadableStream</a></li><li><a href="grpc-ClientUnaryCall.html">ClientUnaryCall</a></li><li><a href="grpc-ClientWritableStream.html">ClientWritableStream</a></li><li><a href="grpc-ServerDuplexStream.html">ServerDuplexStream</a></li><li><a href="grpc-ServerReadableStream.html">ServerReadableStream</a></li><li><a href="grpc-ServerUnaryCall.html">ServerUnaryCall</a></li><li><a href="grpc-ServerWritableStream.html">ServerWritableStream</a></li></ul><h3>Events</h3><ul><li><a href="grpc-ClientDuplexStream.html#event:metadata">metadata</a></li><li><a href="grpc-ClientDuplexStream.html#event:status">status</a></li><li><a href="grpc-ClientReadableStream.html#event:metadata">metadata</a></li><li><a href="grpc-ClientReadableStream.html#event:status">status</a></li><li><a href="grpc-ClientUnaryCall.html#event:metadata">metadata</a></li><li><a href="grpc-ClientUnaryCall.html#event:status">status</a></li><li><a href="grpc-ClientWritableStream.html#event:metadata">metadata</a></li><li><a href="grpc-ClientWritableStream.html#event:status">status</a></li><li><a href="grpc-ServerDuplexStream.html#~event:cancelled">cancelled</a></li><li><a href="grpc-ServerReadableStream.html#~event:cancelled">cancelled</a></li><li><a href="grpc-ServerUnaryCall.html#~event:cancelled">cancelled</a></li><li><a href="grpc-ServerWritableStream.html#~event:cancelled">cancelled</a></li></ul><h3>Namespaces</h3><ul><li><a href="grpc.html">grpc</a></li><li><a href="grpc.credentials.html">credentials</a></li></ul>
  258. </nav>
  259. <br class="clear">
  260. <footer>
  261. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jun 28 2017 09:44:06 GMT-0700 (PDT)
  262. </footer>
  263. <script> prettyPrint(); </script>
  264. <script src="scripts/linenumber.js"> </script>
  265. </body>
  266. </html>