index.js.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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, 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 Metadata = require('./src/metadata.js');
  60. var grpc = require('./src/grpc_extension');
  61. grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii'));
  62. /**
  63. * Load a gRPC object from an existing ProtoBuf.Reflect object.
  64. * @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load.
  65. * @param {Object=} options Options to apply to the loaded object
  66. * @return {Object&lt;string, *>} The resulting gRPC object
  67. */
  68. exports.loadObject = function loadObject(value, options) {
  69. var result = {};
  70. if (value.className === 'Namespace') {
  71. _.each(value.children, function(child) {
  72. result[child.name] = loadObject(child, options);
  73. });
  74. return result;
  75. } else if (value.className === 'Service') {
  76. return client.makeProtobufClientConstructor(value, options);
  77. } else if (value.className === 'Message' || value.className === 'Enum') {
  78. return value.build();
  79. } else {
  80. return value;
  81. }
  82. };
  83. var loadObject = exports.loadObject;
  84. /**
  85. * Load a gRPC object from a .proto file. The options object can provide the
  86. * following options:
  87. * - convertFieldsToCamelCase: Loads this file with that option on protobuf.js
  88. * set as specified. See
  89. * https://github.com/dcodeIO/protobuf.js/wiki/Advanced-options for details
  90. * - binaryAsBase64: deserialize bytes values as base64 strings instead of
  91. * Buffers. Defaults to false
  92. * - longsAsStrings: deserialize long values as strings instead of objects.
  93. * Defaults to true
  94. * - deprecatedArgumentOrder: Use the beta method argument order for client
  95. * methods, with optional arguments after the callback. Defaults to false.
  96. * This option is only a temporary stopgap measure to smooth an API breakage.
  97. * It is deprecated, and new code should not use it.
  98. * @param {string|{root: string, file: string}} filename The file to load
  99. * @param {string=} format The file format to expect. Must be either 'proto' or
  100. * 'json'. Defaults to 'proto'
  101. * @param {Object=} options Options to apply to the loaded file
  102. * @return {Object&lt;string, *>} The resulting gRPC object
  103. */
  104. exports.load = function load(filename, format, options) {
  105. if (!format) {
  106. format = 'proto';
  107. }
  108. var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
  109. if(options &amp;&amp; options.hasOwnProperty('convertFieldsToCamelCase')) {
  110. ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
  111. }
  112. var builder;
  113. try {
  114. switch(format) {
  115. case 'proto':
  116. builder = ProtoBuf.loadProtoFile(filename);
  117. break;
  118. case 'json':
  119. builder = ProtoBuf.loadJsonFile(filename);
  120. break;
  121. default:
  122. throw new Error('Unrecognized format "' + format + '"');
  123. }
  124. } finally {
  125. ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
  126. }
  127. return loadObject(builder.ns, options);
  128. };
  129. /**
  130. * @see module:src/server.Server
  131. */
  132. exports.Server = server.Server;
  133. /**
  134. * @see module:src/metadata
  135. */
  136. exports.Metadata = Metadata;
  137. /**
  138. * Status name to code number mapping
  139. */
  140. exports.status = grpc.status;
  141. /**
  142. * Propagate flag name to number mapping
  143. */
  144. exports.propagate = grpc.propagate;
  145. /**
  146. * Call error name to code number mapping
  147. */
  148. exports.callError = grpc.callError;
  149. /**
  150. * Write flag name to code number mapping
  151. */
  152. exports.writeFlags = grpc.writeFlags;
  153. /**
  154. * Credentials factories
  155. */
  156. exports.credentials = require('./src/credentials.js');
  157. /**
  158. * ServerCredentials factories
  159. */
  160. exports.ServerCredentials = grpc.ServerCredentials;
  161. /**
  162. * @see module:src/client.makeClientConstructor
  163. */
  164. exports.makeGenericClientConstructor = client.makeClientConstructor;
  165. /**
  166. * @see module:src/client.getClientChannel
  167. */
  168. exports.getClientChannel = client.getClientChannel;
  169. /**
  170. * @see module:src/client.waitForClientReady
  171. */
  172. exports.waitForClientReady = client.waitForClientReady;
  173. </code></pre>
  174. </article>
  175. </section>
  176. </div>
  177. <nav>
  178. <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>
  179. </nav>
  180. <br class="clear">
  181. <footer>
  182. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Wed May 11 2016 18:17:25 GMT-0700 (PDT)
  183. </footer>
  184. <script> prettyPrint(); </script>
  185. <script src="scripts/linenumber.js"> </script>
  186. </body>
  187. </html>