index.js.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 _ = require('lodash');
  53. var ProtoBuf = require('protobufjs');
  54. var client = require('./src/client.js');
  55. var server = require('./src/server.js');
  56. var grpc = require('bindings')('grpc');
  57. /**
  58. * Load a gRPC object from an existing ProtoBuf.Reflect object.
  59. * @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load.
  60. * @return {Object&lt;string, *>} The resulting gRPC object
  61. */
  62. exports.loadObject = function loadObject(value) {
  63. var result = {};
  64. if (value.className === 'Namespace') {
  65. _.each(value.children, function(child) {
  66. result[child.name] = loadObject(child);
  67. });
  68. return result;
  69. } else if (value.className === 'Service') {
  70. return client.makeProtobufClientConstructor(value);
  71. } else if (value.className === 'Message' || value.className === 'Enum') {
  72. return value.build();
  73. } else {
  74. return value;
  75. }
  76. };
  77. var loadObject = exports.loadObject;
  78. /**
  79. * Load a gRPC object from a .proto file.
  80. * @param {string} filename The file to load
  81. * @param {string=} format The file format to expect. Must be either 'proto' or
  82. * 'json'. Defaults to 'proto'
  83. * @return {Object&lt;string, *>} The resulting gRPC object
  84. */
  85. exports.load = function load(filename, format) {
  86. if (!format) {
  87. format = 'proto';
  88. }
  89. var builder;
  90. switch(format) {
  91. case 'proto':
  92. builder = ProtoBuf.loadProtoFile(filename);
  93. break;
  94. case 'json':
  95. builder = ProtoBuf.loadJsonFile(filename);
  96. break;
  97. default:
  98. throw new Error('Unrecognized format "' + format + '"');
  99. }
  100. return loadObject(builder.ns);
  101. };
  102. /**
  103. * Get a function that a client can use to update metadata with authentication
  104. * information from a Google Auth credential object, which comes from the
  105. * google-auth-library.
  106. * @param {Object} credential The credential object to use
  107. * @return {function(Object, callback)} Metadata updater function
  108. */
  109. exports.getGoogleAuthDelegate = function getGoogleAuthDelegate(credential) {
  110. /**
  111. * Update a metadata object with authentication information.
  112. * @param {string} authURI The uri to authenticate to
  113. * @param {Object} metadata Metadata object
  114. * @param {function(Error, Object)} callback
  115. */
  116. return function updateMetadata(authURI, metadata, callback) {
  117. metadata = _.clone(metadata);
  118. if (metadata.Authorization) {
  119. metadata.Authorization = _.clone(metadata.Authorization);
  120. } else {
  121. metadata.Authorization = [];
  122. }
  123. credential.getRequestMetadata(authURI, function(err, header) {
  124. if (err) {
  125. callback(err);
  126. return;
  127. }
  128. metadata.Authorization.push(header.Authorization);
  129. callback(null, metadata);
  130. });
  131. };
  132. };
  133. /**
  134. * @see module:src/server.Server
  135. */
  136. exports.Server = server.Server;
  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. * Credentials factories
  151. */
  152. exports.Credentials = grpc.Credentials;
  153. /**
  154. * ServerCredentials factories
  155. */
  156. exports.ServerCredentials = grpc.ServerCredentials;
  157. /**
  158. * @see module:src/client.makeClientConstructor
  159. */
  160. exports.makeGenericClientConstructor = client.makeClientConstructor;
  161. </code></pre>
  162. </article>
  163. </section>
  164. </div>
  165. <nav>
  166. <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_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_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#getGoogleAuthDelegate">getGoogleAuthDelegate</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#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></ul>
  167. </nav>
  168. <br class="clear">
  169. <footer>
  170. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Tue Aug 18 2015 18:25:05 GMT-0700 (PDT)
  171. </footer>
  172. <script> prettyPrint(); </script>
  173. <script src="scripts/linenumber.js"> </script>
  174. </body>
  175. </html>