UNPKG

graph-common

Version:
246 lines (174 loc) 12.7 kB
<!DOCTYPE html> <html> <head> <title>graph.litcoffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="bootstrap.html"> bootstrap.litcoffee </a> <a class="source" href="configuration_manager.html"> configuration_manager.litcoffee </a> <a class="source" href="echo_router.html"> echo_router.litcoffee </a> <a class="source" href="gql.html"> gql.litcoffee </a> <a class="source" href="graph.html"> graph.litcoffee </a> <a class="source" href="index.html"> index.litcoffee </a> <a class="source" href="mongodb_storage.html"> mongodb_storage.litcoffee </a> <a class="source" href="node_manager.html"> node_manager.litcoffee </a> <a class="source" href="node_schema.html"> node_schema.litcoffee </a> <a class="source" href="query.html"> query.litcoffee </a> <a class="source" href="redirect_router.html"> redirect_router.litcoffee </a> <a class="source" href="router_manager.html"> router_manager.litcoffee </a> <a class="source" href="router_schema.html"> router_schema.litcoffee </a> <a class="source" href="schema_manager.html"> schema_manager.litcoffee </a> <a class="source" href="schema_schema.html"> schema_schema.litcoffee </a> <a class="source" href="static_router.html"> static_router.litcoffee </a> <a class="source" href="storage_manager.html"> storage_manager.litcoffee </a> <a class="source" href="storage_router.html"> storage_router.litcoffee </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>graph.litcoffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Graph is the core module. It loads all submodules when instantiate depending on the configuration.</p> </div> <div class="content"><div class='highlight'><pre>GQL = <span class="hljs-literal">null</span> SchemaManager = <span class="hljs-literal">null</span> StorageManager = <span class="hljs-literal">null</span> RouterManager = <span class="hljs-literal">null</span> NodeManager = <span class="hljs-literal">null</span> Bootstrap = <span class="hljs-literal">null</span> Logger = <span class="hljs-literal">null</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Graph</span></span> <span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(configuration_manager, done)</span> -&gt;</span> <span class="hljs-property">@configure</span>(configuration_manager) <span class="hljs-property">@inject</span>() <span class="hljs-property">@instantiate</span>(done) <span class="hljs-attribute">configure</span>: <span class="hljs-function"><span class="hljs-params">(configuration_manager)</span> -&gt;</span> <span class="hljs-property">@configuration_manager</span> = configuration_manager <span class="hljs-property">@configuration</span> = <span class="hljs-property">@configuration_manager</span>.get_configuration() <span class="hljs-attribute">inject</span>: <span class="hljs-function"><span class="hljs-params">()</span> -&gt;</span> di = <span class="hljs-property">@configuration</span>.di <span class="hljs-keyword">or</span> {} GQL = <span class="hljs-built_in">require</span>(di.GQL <span class="hljs-keyword">or</span> <span class="hljs-string">'./gql'</span>) Bootstrap = <span class="hljs-built_in">require</span>(di.Bootstrap <span class="hljs-keyword">or</span> <span class="hljs-string">'./bootstrap'</span>) StorageManager = <span class="hljs-built_in">require</span>(di.StorageManager <span class="hljs-keyword">or</span> <span class="hljs-string">'./storage_manager'</span>) RouterManager = <span class="hljs-built_in">require</span>(di.RouterManager <span class="hljs-keyword">or</span> <span class="hljs-string">'./router_manager'</span>) NodeManager = <span class="hljs-built_in">require</span>(di.NodeManager <span class="hljs-keyword">or</span> <span class="hljs-string">'./node_manager'</span>) SchemaManager = <span class="hljs-built_in">require</span>(di.SchemaManager <span class="hljs-keyword">or</span> <span class="hljs-string">'./schema_manager'</span>) Logger = <span class="hljs-built_in">require</span>(di.Logger <span class="hljs-keyword">or</span> <span class="hljs-string">'winston'</span>) <span class="hljs-attribute">instantiate</span>: <span class="hljs-function"><span class="hljs-params">(done)</span> -&gt;</span> self = @ <span class="hljs-property">@logger</span> = Logger <span class="hljs-property">@logger</span>.cli() <span class="hljs-property">@logger</span>.level = <span class="hljs-property">@configuration</span>.logLevel || <span class="hljs-string">'info'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@configuration</span>.logFile <span class="hljs-property">@logger</span>.add(<span class="hljs-property">@logger</span>.transports.File, { <span class="hljs-attribute">level</span>: <span class="hljs-property">@logger</span>.level, <span class="hljs-attribute">colorize</span>: <span class="hljs-literal">true</span>, <span class="hljs-attribute">json</span>: <span class="hljs-literal">false</span>, <span class="hljs-attribute">filename</span>: <span class="hljs-property">@configuration</span>.logFile }) <span class="hljs-property">@info</span>(<span class="hljs-string">'Logging level set:'</span>, <span class="hljs-property">@logger</span>.level) <span class="hljs-property">@storage_manager</span> = <span class="hljs-keyword">new</span> StorageManager(self, <span class="hljs-property">@configuration</span>.StorageManager) <span class="hljs-property">@database</span> = <span class="hljs-property">@storage_manager</span>.database <span class="hljs-property">@schema_manager</span> = <span class="hljs-keyword">new</span> SchemaManager(self, <span class="hljs-property">@configuration</span>.SchemaManager <span class="hljs-keyword">or</span> { <span class="hljs-string">"Schema"</span>: <span class="hljs-string">"./schema_schema"</span>, <span class="hljs-string">"Node"</span>: <span class="hljs-string">"./node_schema"</span>, <span class="hljs-string">"Router"</span>: <span class="hljs-string">"./router_schema"</span> }) <span class="hljs-property">@node_manager</span> = <span class="hljs-keyword">new</span> NodeManager<span class="hljs-function"><span class="hljs-params">(self, () -&gt; self.router_manager = <span class="hljs-keyword">new</span> RouterManager(self, () -&gt; Bootstrap.bootstrap(self) <span class="hljs-keyword">if</span> Bootstrap self.info(<span class="hljs-string">'Graph API initiated'</span>) done() ) )</span> <span class="hljs-title">run</span>: <span class="hljs-params">(gql, callback)</span> -&gt;</span> <span class="hljs-property">@input</span>(<span class="hljs-string">'GQL&gt;'</span>, gql) self = @ GQL.parse<span class="hljs-function"><span class="hljs-params">(gql, (query) -&gt; self.query(query, callback) )</span> <span class="hljs-title">query</span>: <span class="hljs-params">(query, callback)</span> -&gt;</span> <span class="hljs-property">@debug</span>(<span class="hljs-string">'Graph&gt; Query:'</span>, { <span class="hljs-attribute">node</span>: query.node?.path <span class="hljs-keyword">or</span> query.node, <span class="hljs-attribute">action</span>: query.action, <span class="hljs-attribute">data</span>: query.data} ) query.graph = @ <span class="hljs-property">@node_manager</span>.query(query) <span class="hljs-property">@router_manager</span>.query(query) query.run(callback) <span class="hljs-attribute">disconnect</span>: <span class="hljs-function"><span class="hljs-params">()</span> -&gt;</span> <span class="hljs-property">@database</span>.disconnect() <span class="hljs-property">@info</span>(<span class="hljs-string">'Disconnected'</span>) <span class="hljs-attribute">create_node</span>: <span class="hljs-function"><span class="hljs-params">(node_data)</span> -&gt;</span> <span class="hljs-property">@node_manager</span>.create_node node_data <span class="hljs-attribute">create_router</span>: <span class="hljs-function"><span class="hljs-params">(router_data)</span> -&gt;</span> <span class="hljs-property">@router_manager</span>.create_router router_data <span class="hljs-attribute">log</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log args... <span class="hljs-attribute">error</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.error args... <span class="hljs-attribute">warn</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.warn args... <span class="hljs-attribute">help</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'help'</span>, args... <span class="hljs-attribute">data</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'data'</span>, args... <span class="hljs-attribute">info</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.info args... <span class="hljs-attribute">debug</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'debug'</span>, args... <span class="hljs-attribute">prompt</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'prompt'</span>, args... <span class="hljs-attribute">verbose</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'verbose'</span>, args... <span class="hljs-attribute">input</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'input'</span>, args... <span class="hljs-attribute">silly</span>: <span class="hljs-function"><span class="hljs-params">(args...)</span> -&gt;</span> Logger.log <span class="hljs-string">'silly'</span>, args... <span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = Graph</pre></div></div> </li> </ul> </div> </body> </html>