Files
pluto/docs/concepts/Query.html
T
Julien Eluard 64b2c6e84d Deploy website
Deploy website version based on d9f9755cce
2018-09-21 15:20:56 +02:00

60 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Query · Pluto</title><meta name="viewport" content="width=device-width"/><meta name="generator" content="Docusaurus"/><meta name="description" content="Queries are exposed by the platform in the form of `:queries` key in the capacities map."/><meta property="og:title" content="Query · Pluto"/><meta property="og:type" content="website"/><meta property="og:url" content="https://status-im.github.io/pluto/index.html"/><meta property="og:description" content="Queries are exposed by the platform in the form of `:queries` key in the capacities map."/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/pluto/img/favicon.png"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="/pluto/js/pluto.js"></script><link rel="stylesheet" href="/pluto/css/prism.css"/><link rel="stylesheet" href="/pluto/css/main.css"/></head><body class="sideNavVisible doc separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/pluto/"><img class="logo" src="/pluto/img/logo_white.png" alt="Pluto"/><h2 class="headerTitleWithLogo">Pluto</h2></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class="siteNavGroupActive"><a href="/pluto/docs/Manifesto.html" target="_self">Docs</a></li><li class=""><a href="/pluto/examples.html" target="_self">Examples</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><i></i></div><h2><i></i><span>Concepts</span></h2><div class="tocToggler" id="tocToggler"><i class="icon-toc"></i></div></div><div class="navGroups"><div class="navGroup navGroupActive"><h3>Getting Started</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/Manifesto.html">Manifesto</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/Principles.html">Principles</a></li></ul></div><div class="navGroup navGroupActive"><h3>Concepts</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Anatomy.html">Anatomy of an extension</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Hook.html">Hook</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/View.html">View</a></li><li class="navListItem navListItemActive"><a class="navItem navItemActive" href="/pluto/docs/concepts/Query.html">Query</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Event.html">Event</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Registry.html">Registry</a></li></ul></div><div class="navGroup navGroupActive"><h3>Build</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/build/Packaging.html">Packaging</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/build/Deployment.html">Deployment</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/build/FirstExtension.html">My first extension</a></li></ul></div><div class="navGroup navGroupActive"><h3>Contributing</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/Development.html">Development</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/Roadmap.html">Roadmap</a></li></ul></div></div></section></div><script>
document.addEventListener('DOMContentLoaded', function() {
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
createToggler('#tocToggler', 'body', 'tocActive');
const headings = document.querySelector('.toc-headings');
headings && headings.addEventListener('click', function(event) {
if (event.target.tagName === 'A') {
document.body.classList.remove('tocActive');
}
}, false);
function createToggler(togglerSelector, targetSelector, className) {
var toggler = document.querySelector(togglerSelector);
var target = document.querySelector(targetSelector);
toggler.onclick = function(event) {
event.preventDefault();
target.classList.toggle(className);
};
}
});
</script></nav></div><div class="container mainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><h1>Query</h1></header><article><div><span><p>Queries are exposed by the platform in the form of <code>:queries</code> key in the capacities map.
Only those queries which are exposed can be either referenced by hook property (when the property is of the type <code>:query</code>),
or used to read data in let block in view (eq <code>(let [network-name (query [:get-in [:network :name]])] [text {} network-name])</code>).</p>
<h2><a class="anchor" aria-hidden="true" id="query-as-hook-property"></a><a href="#query-as-hook-property" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Query as hook property</h2>
<p>To refer to some query via hook property (might be required for some host app hooks), the property must be defined as <code>:query</code> type
by the app-hook and extension must correctly refer to query from capacities map.</p>
<h3><a class="anchor" aria-hidden="true" id="example"></a><a href="#example" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Example</h3>
<pre><code class="hljs css languages- clojure"><span class="token comment">;; App hook code in host application</span>
<span class="token punctuation">(</span>reify host/AppHook
<span class="token punctuation">(</span>id <span class="token punctuation">[</span>_<span class="token punctuation">]</span> <span class="token operator">:wallet-asset</span><span class="token punctuation">)</span>
<span class="token punctuation">(</span>properties <span class="token punctuation">[</span>_<span class="token punctuation">]</span> <span class="token punctuation">{</span><span class="token operator">:able-to-send</span> <span class="token operator">:query</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token comment">;; Capacities map in the host application</span>
<span class="token punctuation">{</span><span class="token operator">:capacities</span> <span class="token punctuation">{</span><span class="token operator">:queries</span> #<span class="token punctuation">{</span><span class="token operator">:network-up</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">}</span>
<span class="token comment">;; Extension hook data</span>
hooks/wallet-asset.next-coin
<span class="token punctuation">{</span><span class="token operator">:able-to-send</span> <span class="token operator">:network-up</span><span class="token punctuation">}</span>
</code></pre>
<h2><a class="anchor" aria-hidden="true" id="queries-in-views"></a><a href="#queries-in-views" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Queries in views</h2>
<p>To use some queries in extension defined view, the query must be exposed via capacities map of the host platform.</p>
<h2><a class="anchor" aria-hidden="true" id="example-1"></a><a href="#example-1" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Example</h2>
<pre><code class="hljs css languages- clojure"><span class="token comment">;; Capacities map in the host application</span>
<span class="token punctuation">{</span><span class="token operator">:capacities</span> <span class="token punctuation">{</span><span class="token operator">:queries</span> #<span class="token punctuation">{</span><span class="token operator">:get-in</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">}</span>
<span class="token comment">;; Extension view data</span>
views/coin-item
<span class="token punctuation">[</span>view <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">(</span><span class="token keyword">let</span> <span class="token punctuation">[</span>current-network <span class="token punctuation">(</span>query <span class="token punctuation">[</span><span class="token operator">:get-in</span> <span class="token punctuation">[</span><span class="token operator">:networks</span> <span class="token operator">:current</span> <span class="token operator">:name</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span>text <span class="token punctuation">{</span><span class="token punctuation">}</span> <span class="token string">"Current network: "</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span>text <span class="token punctuation">{</span><span class="token punctuation">}</span> current-network<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre>
<h2><a class="anchor" aria-hidden="true" id="queries-permission-checking"></a><a href="#queries-permission-checking" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Queries permission checking</h2>
<p>There is a special treatment for generic query <code>:get-in</code> where it's data path (where to read data from app-state exposed by host platform)
is checked against the declared <code>[:permissions :read]</code> map in the capacities.
Whenever this check fails (extension is reading data in view not exposed the host), meaningfull parse error will be produced.</p>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="View.html">← View</a><a class="docs-next button" href="Event.html">Event →</a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#query-as-hook-property">Query as hook property</a><ul class="toc-headings"><li><a href="#example">Example</a></li></ul></li><li><a href="#queries-in-views">Queries in views</a></li><li><a href="#example-1">Example</a></li><li><a href="#queries-permission-checking">Queries permission checking</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/pluto/" class="nav-home"><img src="/pluto/img/logo_white.png" alt="Pluto" width="66" height="58"/></a><div><h5>Docs</h5><a href="docs/Tutorial">Getting Started</a><a href="docs/API">API Reference</a></div><div><h5>Community</h5><a href="https://chat.status.im">Project Chat</a><a href="https://twitter.com/ethstatus" target="_blank" rel="noreferrer noopener">Twitter</a></div><div><h5>More</h5><a href="https://blog.status.im/">Blog</a><a href="https://github.com/status-im/pluto/">GitHub</a></div></section><section class="copyright">Copyright © 2018 Status.im</section></footer></div></body></html>