UNPKG

graph-common

Version:
187 lines (130 loc) 7.61 kB
<!DOCTYPE html> <html> <head> <title>schema_manager.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>schema_manager.litcoffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>SchemaManager takes care of schemas and models and their loading</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SchemaManager</span></span> <span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(graph, core_model_mapping)</span> -&gt;</span> self = @ <span class="hljs-property">@graph</span> = graph <span class="hljs-property">@database</span> = <span class="hljs-property">@graph</span>.database <span class="hljs-property">@schemas</span> = [] <span class="hljs-property">@models</span> = [] <span class="hljs-property">@core_model_mapping</span> = core_model_mapping <span class="hljs-property">@init_core_model</span><span class="hljs-function"><span class="hljs-params">(() -&gt; self.reload())</span> <span class="hljs-title">load_core_model</span>: <span class="hljs-params">(name, file)</span> -&gt;</span> model_definition = <span class="hljs-built_in">require</span>(file) schema = model_definition.schema methods = model_definition.methods <span class="hljs-property">@load_schema</span><span class="hljs-function"><span class="hljs-params">(schema, (schema_object) -&gt; Object.keys(model_definition.methods).forEach((method) -&gt; schema_object.methods[method] = model_definition.methods[method]))</span> @<span class="hljs-title">model</span><span class="hljs-params">(name)</span> <span class="hljs-title">init_core_model</span>: <span class="hljs-params">(done)</span> -&gt;</span> <span class="hljs-keyword">for</span> core_model, file <span class="hljs-keyword">of</span> <span class="hljs-property">@core_model_mapping</span> <span class="hljs-property">@load_core_model</span>(core_model, file) done() <span class="hljs-attribute">reload</span>: <span class="hljs-function"><span class="hljs-params">()</span> -&gt;</span> Schema = <span class="hljs-property">@model</span>(<span class="hljs-string">'Schema'</span>) Schema.find<span class="hljs-function"><span class="hljs-params">({}, (err, schemas) -&gt; schemas.forEach((schema) -&gt; <span class="hljs-property">@load_schema</span>(schema)))</span> <span class="hljs-title">load_schema</span>: <span class="hljs-params">(schema, callback)</span> -&gt;</span> <span class="hljs-property">@graph</span>.verbose(<span class="hljs-string">'SchemaManager&gt; add:'</span>, schema.name) Schema = <span class="hljs-property">@database</span>.Schema <span class="hljs-property">@schemas</span>[schema.name] = <span class="hljs-keyword">new</span> Schema(schema.definition) <span class="hljs-property">@database</span>.apply_plugins(<span class="hljs-property">@schemas</span>[schema.name]) callback(<span class="hljs-property">@schemas</span>[schema.name]) <span class="hljs-keyword">if</span> callback <span class="hljs-attribute">model</span>: <span class="hljs-function"><span class="hljs-params">(schema_name)</span> -&gt;</span> <span class="hljs-keyword">return</span> <span class="hljs-property">@models</span>[schema_name] <span class="hljs-keyword">if</span> <span class="hljs-property">@models</span>[schema_name] <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@schemas</span>[schema_name] <span class="hljs-property">@models</span>[schema_name] = <span class="hljs-property">@database</span>.model(schema_name, <span class="hljs-property">@schemas</span>[schema_name]) <span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = SchemaManager</pre></div></div> </li> </ul> </div> </body> </html>