index.js.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. *
  21. * Copyright 2015-2016, 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 SSL_ROOTS_PATH = path.resolve(__dirname, '..', '..', 'etc', 'roots.pem');
  54. if (!process.env.GRPC_DEFAULT_SSL_ROOTS_FILE_PATH) {
  55. process.env.GRPC_DEFAULT_SSL_ROOTS_FILE_PATH = SSL_ROOTS_PATH;
  56. }
  57. var _ = require('lodash');
  58. var ProtoBuf = require('protobufjs');
  59. var client = require('./src/client.js');
  60. var server = require('./src/server.js');
  61. var Metadata = require('./src/metadata.js');
  62. var grpc = require('./src/grpc_extension');
  63. /**
  64. * Load a gRPC object from an existing ProtoBuf.Reflect object.
  65. * @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load.
  66. * @param {Object=} options Options to apply to the loaded object
  67. * @return {Object&lt;string, *>} The resulting gRPC object
  68. */
  69. exports.loadObject = function loadObject(value, options) {
  70. var result = {};
  71. if (value.className === 'Namespace') {
  72. _.each(value.children, function(child) {
  73. result[child.name] = loadObject(child, options);
  74. });
  75. return result;
  76. } else if (value.className === 'Service') {
  77. return client.makeProtobufClientConstructor(value, options);
  78. } else if (value.className === 'Message' || value.className === 'Enum') {
  79. return value.build();
  80. } else {
  81. return value;
  82. }
  83. };
  84. var loadObject = exports.loadObject;
  85. /**
  86. * Load a gRPC object from a .proto file. The options object can provide the
  87. * following options:
  88. * - convertFieldsToCamelCase: Loads this file with that option on protobuf.js
  89. * set as specified. See
  90. * https://github.com/dcodeIO/protobuf.js/wiki/Advanced-options for details
  91. * - binaryAsBase64: deserialize bytes values as base64 strings instead of
  92. * Buffers. Defaults to false
  93. * - longsAsStrings: deserialize long values as strings instead of objects.
  94. * Defaults to true
  95. * @param {string|{root: string, file: string}} filename The file to load
  96. * @param {string=} format The file format to expect. Must be either 'proto' or
  97. * 'json'. Defaults to 'proto'
  98. * @param {Object=} options Options to apply to the loaded file
  99. * @return {Object&lt;string, *>} The resulting gRPC object
  100. */
  101. exports.load = function load(filename, format, options) {
  102. if (!format) {
  103. format = 'proto';
  104. }
  105. var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
  106. if(options &amp;&amp; options.hasOwnProperty('convertFieldsToCamelCase')) {
  107. ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
  108. }
  109. var builder;
  110. try {
  111. switch(format) {
  112. case 'proto':
  113. builder = ProtoBuf.loadProtoFile(filename);
  114. break;
  115. case 'json':
  116. builder = ProtoBuf.loadJsonFile(filename);
  117. break;
  118. default:
  119. throw new Error('Unrecognized format "' + format + '"');
  120. }
  121. } finally {
  122. ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
  123. }
  124. return loadObject(builder.ns, options);
  125. };
  126. /**
  127. * @see module:src/server.Server
  128. */
  129. exports.Server = server.Server;
  130. /**
  131. * @see module:src/metadata
  132. */
  133. exports.Metadata = Metadata;
  134. /**
  135. * Status name to code number mapping
  136. */
  137. exports.status = grpc.status;
  138. /**
  139. * Propagate flag name to number mapping
  140. */
  141. exports.propagate = grpc.propagate;
  142. /**
  143. * Call error name to code number mapping
  144. */
  145. exports.callError = grpc.callError;
  146. /**
  147. * Write flag name to code number mapping
  148. */
  149. exports.writeFlags = grpc.writeFlags;
  150. /**
  151. * Credentials factories
  152. */
  153. exports.credentials = require('./src/credentials.js');
  154. /**
  155. * ServerCredentials factories
  156. */
  157. exports.ServerCredentials = grpc.ServerCredentials;
  158. /**
  159. * @see module:src/client.makeClientConstructor
  160. */
  161. exports.makeGenericClientConstructor = client.makeClientConstructor;
  162. /**
  163. * @see module:src/client.getClientChannel
  164. */
  165. exports.getClientChannel = client.getClientChannel;
  166. /**
  167. * @see module:src/client.waitForClientReady
  168. */
  169. exports.waitForClientReady = client.waitForClientReady;
  170. </code></pre>
  171. </article>
  172. </section>
  173. </div>
  174. <nav>
  175. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-src_client.html">src/client</a></li><li><a href="module-src_common.html">src/common</a></li><li><a href="module-src_credentials.html">src/credentials</a></li><li><a href="module-src_metadata.html">src/metadata</a></li><li><a href="module-src_server.html">src/server</a></li></ul><h3>Classes</h3><ul><li><a href="module-src_client.makeClientConstructor-Client.html">Client</a></li><li><a href="module-src_client-ClientDuplexStream.html">ClientDuplexStream</a></li><li><a href="module-src_client-ClientReadableStream.html">ClientReadableStream</a></li><li><a href="module-src_client-ClientWritableStream.html">ClientWritableStream</a></li><li><a href="module-src_metadata-Metadata.html">Metadata</a></li><li><a href="module-src_server-Server.html">Server</a></li><li><a href="module-src_server-ServerDuplexStream.html">ServerDuplexStream</a></li><li><a href="module-src_server-ServerReadableStream.html">ServerReadableStream</a></li><li><a href="module-src_server-ServerWritableStream.html">ServerWritableStream</a></li></ul><h3>Global</h3><ul><li><a href="global.html#callError">callError</a></li><li><a href="global.html#credentials">credentials</a></li><li><a href="global.html#getClientChannel">getClientChannel</a></li><li><a href="global.html#load">load</a></li><li><a href="global.html#loadObject">loadObject</a></li><li><a href="global.html#makeGenericClientConstructor">makeGenericClientConstructor</a></li><li><a href="global.html#Metadata">Metadata</a></li><li><a href="global.html#propagate">propagate</a></li><li><a href="global.html#Server">Server</a></li><li><a href="global.html#ServerCredentials">ServerCredentials</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#waitForClientReady">waitForClientReady</a></li><li><a href="global.html#writeFlags">writeFlags</a></li></ul>
  176. </nav>
  177. <br class="clear">
  178. <footer>
  179. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Mar 08 2016 10:29:45 GMT-0800 (PST)
  180. </footer>
  181. <script> prettyPrint(); </script>
  182. <script src="scripts/linenumber.js"> </script>
  183. </body>
  184. </html>