apollo-passport-rethinkdbdash
Version:
rethinkdbdash driver for apollo-passport
1,911 lines (503 loc) • 22.7 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: RethinkDBDashDriver</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: RethinkDBDashDriver</h1>
<section>
<header>
<h2>RethinkDBDashDriver</h2>
<div class="class-description"><p>Class implementing the Apollo Passport DBDriver interface</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="RethinkDBDashDriver"><span class="type-signature"></span>new RethinkDBDashDriver<span class="signature">(r,)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Returns a DBDriver instance (for use by Apollo Passport). Parameters are
driver-specific and should be clearly specificied in the README.
This documents the RethinkDBDash DBDriver specifically, although some
<em>options</em> are relevant for all drivers.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>r,</code></td>
<td class="type">
<span class="param-type">rethinkdbdash</span>
</td>
<td class="description last"><p>e.g. var r = require('rethinkdbdash')();</p></td>
</tr>
<tr>
<td class="name"><code>options.userTableName</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>default: 'users'</p></td>
</tr>
<tr>
<td class="name"><code>options.configTableName</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>default: 'apolloPassportConfig'</p></td>
</tr>
<tr>
<td class="name"><code>options.dbName</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>default: current database</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line4">line 4</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_assertTableExists"><span class="type-signature"></span>_assertTableExists<span class="signature">(name)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Internal method, documented for benefit of driver authors. Asserts (and
awaits) that the given table name exists. This is a convenience for the
user but with RethinkDB <strong>there is no safe way to do this</strong> other than
creating the table in advance (outside of the app). It's fine if the
table is created with only one app instance running, which is usually
the case for initial setup.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the name of the table to assert</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line76">line 76</a>
</li></ul></dd>
</dl>
<h4 class="name" id="_init"><span class="type-signature"></span>_init<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Internal method, documented for benefit of driver authors. Most important
is to call fetchConfig() (XXX unfinished), but may also assert that all
tables exist, and run ready callbacks.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line36">line 36</a>
</li></ul></dd>
</dl>
<h4 class="name" id="_ready"><span class="type-signature"></span>_ready<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Internal method, documented for benefit of driver authors. An awaitable
promise that returns if the driver is ready (or when it becomes ready).</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line53">line 53</a>
</li></ul></dd>
</dl>
<h4 class="name" id="assertUserEmailData"><span class="type-signature"></span>assertUserEmailData<span class="signature">(userId, email, data)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Given a userId, ensures the user record contains the given email
address, and updates it with optional data.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>userId</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the id of the user to assert</p></td>
</tr>
<tr>
<td class="name"><code>email</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the email address to ensure exists</p></td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>optional, e.g. { type: 'work', verified: true }</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line233">line 233</a>
</li></ul></dd>
</dl>
<h4 class="name" id="assertUserServiceData"><span class="type-signature"></span>assertUserServiceData<span class="signature">(userId, service, data)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Given a userId, ensure the user record contains the given service
record, and updates it with the given data.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>userId</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the id of the user to assert</p></td>
</tr>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the name of the service, e.g. "facebook"</p></td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>e.g. { id: "4321", displayName: "John Sheppard" }</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line251">line 251</a>
</li></ul></dd>
</dl>
<h4 class="name" id="createUser"><span class="type-signature"></span>createUser<span class="signature">(user)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Given a user record, save it to the database, and return its given id.
NoSQL databases should store the entire object, schema-based databases
should honor the 'emails' and 'services' keys and store as necessary
in another table.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>user</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>{
emails: [ { address: "me@me.com" } ],
services: [ { facebook: { id: 1, ...profile } } ]
...anyOtherDataForUserRecordAtCreationTimeFromAppHooks
}</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line155">line 155</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>the id of the inserted user record</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="fetchConfig"><span class="type-signature"></span>fetchConfig<span class="signature">()</span><span class="type-signature"> → {object}</span></h4>
<div class="description">
<p>Retrieves <em>all</em> configuration from the database.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line105">line 105</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>A nested dictionary arranged by type, i.e.</p>
<pre class="prettyprint source lang-js"><code> {
service: { // type
facebook: { // id
...data // value (de-JSONified if from non-document DB)
}
}
}</code></pre>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="fetchUserByEmail"><span class="type-signature"></span>fetchUserByEmail<span class="signature">(email)</span><span class="type-signature"> → {object}</span></h4>
<div class="description">
<p>Given a single "email" param, returns the matching user record if one
exists, or null, otherwise.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>email</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the email address to search for, e.g. "me@me.com"</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line190">line 190</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>user object in the same format expected by
<a href="RethinkDBDashDriver.html#createUser">RethinkDBDashDriver#createUser</a>, or <em>null</em> if none found.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="fetchUserById"><span class="type-signature"></span>fetchUserById<span class="signature">(id)</span><span class="type-signature"> → {object}</span></h4>
<div class="description">
<p>Fetches a user record by id. Schema-based databases should merge
appropriate user-data from e.g. <code>user_emails</code> and <code>user_services</code>.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the user record's id</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line176">line 176</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>user object in the same format expected by
<a href="RethinkDBDashDriver.html#createUser">RethinkDBDashDriver#createUser</a>, or <em>null</em> if none found.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="fetchUserByServiceIdOrEmail"><span class="type-signature"></span>fetchUserByServiceIdOrEmail<span class="signature">(service, id, email)</span><span class="type-signature"> → {object}</span></h4>
<div class="description">
<p>Returns a user who has <em>either</em> a matching email address or matching
service record, or null, otherwise.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>name of the service, e.g. "facebook"</p></td>
</tr>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>id of the service record, e.g. "152356242"</p></td>
</tr>
<tr>
<td class="name"><code>email</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the email address to search for, e.g. "me@me.com"</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line212">line 212</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>user object in the same format expected by
<a href="RethinkDBDashDriver.html#createUser">RethinkDBDashDriver#createUser</a>, or <em>null</em> if none found</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="setConfigKey"><span class="type-signature"></span>setConfigKey<span class="signature">(type, id, value)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Creates or updates the key with the given value.
NoSQL databases can store the destructured value as part of the record.
Fixed-schema databases should JSON-encode the 'value' column.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>e.g. "service"</p></td>
</tr>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>e.g. "facebook"</p></td>
</tr>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>e.g. { id: 1, ...profile }</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line130">line 130</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RethinkDBDashDriver.html">RethinkDBDashDriver</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sat Aug 20 2016 13:51:25 GMT+0300 (IDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>