triplecheck-repository-firestore
Version:
Database utility for using Firestore with TripleCheck broker.
137 lines (133 loc) • 8.42 kB
HTML
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>triplecheck-repository-firestore</title>
<meta name="description" content="Documentation for triplecheck-repository-firestore">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">triplecheck-repository-firestore</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<h1>triplecheck-repository-firestore</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<a href="#triplecheck-repository-firestore" id="triplecheck-repository-firestore" style="color: inherit; text-decoration: none;">
<h1>triplecheck-repository-firestore</h1>
</a>
<p><img src="readme/triplecheck-repository.png" alt="TripleCheck database repository"></p>
<a href="#triplecheck-firestore-database-repository" id="triplecheck-firestore-database-repository" style="color: inherit; text-decoration: none;">
<h2>TripleCheck: Firestore database repository</h2>
</a>
<p>Database utility for using Firestore with TripleCheck broker. It implements the repository base at <a href="https://github.com/mikaelvesavuori/triplecheck-core">triplecheck-core</a>.</p>
<a href="#instructions" id="instructions" style="color: inherit; text-decoration: none;">
<h2>Instructions</h2>
</a>
<p>In your <code>triplecheck-broker</code> implementation, do a regular import for <code>triplecheck-repository-firestore</code> and pass the repository to the broker. A basic implementation could look like:</p>
<pre><code class="language-TypeScript"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">FirestoreRepository</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">'triplecheck-repository-firestore'</span><span style="color: #000000">;</span>
<span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">TripleCheckBroker</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">'triplecheck-broker'</span><span style="color: #000000">;</span>
<span style="color: #008000">// If inside Google Cloud Platform:</span>
<span style="color: #008000">// Pass the repo your Firestore configuration and the collection name</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">repository</span><span style="color: #000000"> = </span><span style="color: #795E26">FirestoreRepository</span><span style="color: #000000">(</span><span style="color: #0000FF">undefined</span><span style="color: #000000">, </span><span style="color: #A31515">"your-database-name"</span><span style="color: #000000">);</span>
<span style="color: #008000">// If outside Google Cloud Platform:</span>
<span style="color: #008000">// Pass the repo your Firestore configuration and the collection name</span>
<span style="color: #008000">// Keyfile/config only needed when running outside of GCP context</span>
<span style="color: #008000">// @see https://cloud.google.com/firestore/docs/quickstart-servers</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">repository</span><span style="color: #000000"> = </span><span style="color: #795E26">FirestoreRepository</span><span style="color: #000000">({</span>
<span style="color: #000000"> </span><span style="color: #001080">projectId:</span><span style="color: #000000"> </span><span style="color: #A31515">'your-project-id'</span><span style="color: #000000">,</span>
<span style="color: #000000"> </span><span style="color: #001080">keyFilename:</span><span style="color: #000000"> </span><span style="color: #A31515">'keyfile.json'</span>
<span style="color: #000000">}, </span><span style="color: #A31515">"your-database-name"</span><span style="color: #000000">);</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">request</span><span style="color: #000000"> = </span><span style="color: #A31515">"Get this from your API request and transform it as needed"</span><span style="color: #000000">;</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">payload</span><span style="color: #000000"> = </span><span style="color: #A31515">"Body"</span><span style="color: #000000">;</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> { </span><span style="color: #0070C1">responseData</span><span style="color: #000000">, </span><span style="color: #0070C1">status</span><span style="color: #000000">, </span><span style="color: #0070C1">headers</span><span style="color: #000000"> } = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #795E26">TripleCheckBroker</span><span style="color: #000000">(</span>
<span style="color: #000000"> </span><span style="color: #001080">request</span><span style="color: #000000">,</span>
<span style="color: #000000"> </span><span style="color: #001080">payload</span><span style="color: #000000">,</span>
<span style="color: #000000"> </span><span style="color: #001080">repository</span>
<span style="color: #000000">);</span>
</code></pre>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class=" ">
<a href="modules.html">Exports</a>
</li>
<li class=" tsd-kind-module">
<a href="modules/firestorerepository.html">Firestore<wbr>Repository</a>
</li>
<li class=" tsd-kind-module">
<a href="modules/index.html">index</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>