index.js.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 gRPC authors.
  22. *
  23. * Licensed under the Apache License, Version 2.0 (the "License");
  24. * you may not use this file except in compliance with the License.
  25. * You may obtain a copy of the License at
  26. *
  27. * http://www.apache.org/licenses/LICENSE-2.0
  28. *
  29. * Unless required by applicable law or agreed to in writing, software
  30. * distributed under the License is distributed on an "AS IS" BASIS,
  31. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32. * See the License for the specific language governing permissions and
  33. * limitations under the License.
  34. *
  35. */
  36. 'use strict';
  37. var path = require('path');
  38. var fs = require('fs');
  39. var SSL_ROOTS_PATH = path.resolve(__dirname, '..', '..', 'etc', 'roots.pem');
  40. var _ = require('lodash');
  41. var ProtoBuf = require('protobufjs');
  42. var client = require('./src/client.js');
  43. var server = require('./src/server.js');
  44. var common = require('./src/common.js');
  45. var Metadata = require('./src/metadata.js');
  46. var grpc = require('./src/grpc_extension');
  47. var protobuf_js_5_common = require('./src/protobuf_js_5_common');
  48. var protobuf_js_6_common = require('./src/protobuf_js_6_common');
  49. var constants = require('./src/constants.js');
  50. grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii'));
  51. /**
  52. * @namespace grpc
  53. */
  54. /**
  55. * Load a ProtoBuf.js object as a gRPC object.
  56. * @memberof grpc
  57. * @alias grpc.loadObject
  58. * @param {Object} value The ProtoBuf.js reflection object to load
  59. * @param {Object=} options Options to apply to the loaded file
  60. * @param {bool=} [options.binaryAsBase64=false] deserialize bytes values as
  61. * base64 strings instead of Buffers
  62. * @param {bool=} [options.longsAsStrings=true] deserialize long values as
  63. * strings instead of objects
  64. * @param {bool=} [options.enumsAsStrings=true] deserialize enum values as
  65. * strings instead of numbers. Only works with Protobuf.js 6 values.
  66. * @param {bool=} [options.deprecatedArgumentOrder=false] use the beta method
  67. * argument order for client methods, with optional arguments after the
  68. * callback. This option is only a temporary stopgap measure to smooth an
  69. * API breakage. It is deprecated, and new code should not use it.
  70. * @param {(number|string)=} [options.protobufjsVersion='detect'] 5 and 6
  71. * respectively indicate that an object from the corresponding version of
  72. * Protobuf.js is provided in the value argument. If the option is 'detect',
  73. * gRPC wll guess what the version is based on the structure of the value.
  74. * @return {Object&lt;string, *>} The resulting gRPC object.
  75. */
  76. exports.loadObject = function loadObject(value, options) {
  77. options = _.defaults(options, common.defaultGrpcOptions);
  78. options = _.defaults(options, {'protobufjsVersion': 'detect'});
  79. var protobufjsVersion;
  80. if (options.protobufjsVersion === 'detect') {
  81. if (protobuf_js_6_common.isProbablyProtobufJs6(value)) {
  82. protobufjsVersion = 6;
  83. } else if (protobuf_js_5_common.isProbablyProtobufJs5(value)) {
  84. protobufjsVersion = 5;
  85. } else {
  86. var error_message = 'Could not detect ProtoBuf.js version. Please ' +
  87. 'specify the version number with the "protobufjs_version" option';
  88. throw new Error(error_message);
  89. }
  90. } else {
  91. protobufjsVersion = options.protobufjsVersion;
  92. }
  93. switch (protobufjsVersion) {
  94. case 6: return protobuf_js_6_common.loadObject(value, options);
  95. case 5:
  96. return protobuf_js_5_common.loadObject(value, options);
  97. default:
  98. throw new Error('Unrecognized protobufjsVersion', protobufjsVersion);
  99. }
  100. };
  101. var loadObject = exports.loadObject;
  102. /**
  103. * Load a gRPC object from a .proto file.
  104. * @memberof grpc
  105. * @alias grpc.load
  106. * @param {string|{root: string, file: string}} filename The file to load
  107. * @param {string=} format The file format to expect. Must be either 'proto' or
  108. * 'json'. Defaults to 'proto'
  109. * @param {Object=} options Options to apply to the loaded file
  110. * @param {bool=} [options.convertFieldsToCamelCase=false] Load this file with
  111. * field names in camel case instead of their original case
  112. * @param {bool=} [options.binaryAsBase64=false] deserialize bytes values as
  113. * base64 strings instead of Buffers
  114. * @param {bool=} [options.longsAsStrings=true] deserialize long values as
  115. * strings instead of objects
  116. * @param {bool=} [options.deprecatedArgumentOrder=false] use the beta method
  117. * argument order for client methods, with optional arguments after the
  118. * callback. This option is only a temporary stopgap measure to smooth an
  119. * API breakage. It is deprecated, and new code should not use it.
  120. * @return {Object&lt;string, *>} The resulting gRPC object
  121. */
  122. exports.load = function load(filename, format, options) {
  123. options = _.defaults(options, common.defaultGrpcOptions);
  124. options.protobufjsVersion = 5;
  125. if (!format) {
  126. format = 'proto';
  127. }
  128. var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
  129. if(options &amp;&amp; options.hasOwnProperty('convertFieldsToCamelCase')) {
  130. ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
  131. }
  132. var builder;
  133. try {
  134. switch(format) {
  135. case 'proto':
  136. builder = ProtoBuf.loadProtoFile(filename);
  137. break;
  138. case 'json':
  139. builder = ProtoBuf.loadJsonFile(filename);
  140. break;
  141. default:
  142. throw new Error('Unrecognized format "' + format + '"');
  143. }
  144. } finally {
  145. ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
  146. }
  147. return loadObject(builder.ns, options);
  148. };
  149. var log_template = _.template(
  150. '{severity} {timestamp}\t{file}:{line}]\t{message}',
  151. {interpolate: /{([\s\S]+?)}/g});
  152. /**
  153. * Sets the logger function for the gRPC module. For debugging purposes, the C
  154. * core will log synchronously directly to stdout unless this function is
  155. * called. Note: the output format here is intended to be informational, and
  156. * is not guaranteed to stay the same in the future.
  157. * Logs will be directed to logger.error.
  158. * @memberof grpc
  159. * @alias grpc.setLogger
  160. * @param {Console} logger A Console-like object.
  161. */
  162. exports.setLogger = function setLogger(logger) {
  163. common.logger = logger;
  164. grpc.setDefaultLoggerCallback(function(file, line, severity,
  165. message, timestamp) {
  166. logger.error(log_template({
  167. file: path.basename(file),
  168. line: line,
  169. severity: severity,
  170. message: message,
  171. timestamp: timestamp.toISOString()
  172. }));
  173. });
  174. };
  175. /**
  176. * Sets the logger verbosity for gRPC module logging. The options are members
  177. * of the grpc.logVerbosity map.
  178. * @memberof grpc
  179. * @alias grpc.setLogVerbosity
  180. * @param {Number} verbosity The minimum severity to log
  181. */
  182. exports.setLogVerbosity = function setLogVerbosity(verbosity) {
  183. common.logVerbosity = verbosity;
  184. grpc.setLogVerbosity(verbosity);
  185. };
  186. exports.Server = server.Server;
  187. exports.Metadata = Metadata;
  188. exports.status = constants.status;
  189. exports.propagate = constants.propagate;
  190. exports.callError = constants.callError;
  191. exports.writeFlags = constants.writeFlags;
  192. exports.logVerbosity = constants.logVerbosity;
  193. exports.credentials = require('./src/credentials.js');
  194. /**
  195. * ServerCredentials factories
  196. * @constructor ServerCredentials
  197. * @memberof grpc
  198. */
  199. exports.ServerCredentials = grpc.ServerCredentials;
  200. /**
  201. * Create insecure server credentials
  202. * @name grpc.ServerCredentials.createInsecure
  203. * @kind function
  204. * @return grpc.ServerCredentials
  205. */
  206. /**
  207. * A private key and certificate pair
  208. * @typedef {Object} grpc.ServerCredentials~keyCertPair
  209. * @property {Buffer} privateKey The server's private key
  210. * @property {Buffer} certChain The server's certificate chain
  211. */
  212. /**
  213. * Create SSL server credentials
  214. * @name grpc.ServerCredentials.createInsecure
  215. * @kind function
  216. * @param {?Buffer} rootCerts Root CA certificates for validating client
  217. * certificates
  218. * @param {Array&lt;grpc.ServerCredentials~keyCertPair>} keyCertPairs A list of
  219. * private key and certificate chain pairs to be used for authenticating
  220. * the server
  221. * @param {boolean} [checkClientCertificate=false] Indicates that the server
  222. * should request and verify the client's certificates
  223. * @return grpc.ServerCredentials
  224. */
  225. exports.makeGenericClientConstructor = client.makeClientConstructor;
  226. exports.getClientChannel = client.getClientChannel;
  227. exports.waitForClientReady = client.waitForClientReady;
  228. /**
  229. * @memberof grpc
  230. * @alias grpc.closeClient
  231. * @param {grpc.Client} client_obj The client to close
  232. */
  233. exports.closeClient = function closeClient(client_obj) {
  234. client.Client.prototype.close.apply(client_obj);
  235. };
  236. exports.Client = client.Client;
  237. </code></pre>
  238. </article>
  239. </section>
  240. </div>
  241. <nav>
  242. <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>
  243. </nav>
  244. <br class="clear">
  245. <footer>
  246. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.3</a> on Fri Sep 08 2017 11:10:31 GMT-0700 (PDT)
  247. </footer>
  248. <script> prettyPrint(); </script>
  249. <script src="scripts/linenumber.js"> </script>
  250. </body>
  251. </html>