UNPKG

ink-docstrap

Version:

[![NPM](https://nodei.co/npm/ink-docstrap.png?downloads=true)](https://nodei.co/npm/ink-docstrap/)

2,377 lines (908 loc) 33.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>DocStrap Mixin: documents/schema</title> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css"> <link type="text/css" rel="stylesheet" href="styles/site.cerulean.css"> </head> <body> <div class="container-fluid"> <div class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <a class="brand" href="index.html">DocStrap</a> <ul class="nav"> <li class="dropdown"> <a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b class="caret"></b></a> <ul class="dropdown-menu "> <li> <a href="module-base.html">base</a> </li> <li> <a href="chains_.html">base/chains</a> </li> <li> <a href="binder.html">documents/binder</a> </li> <li> <a href="model_.html">documents/model</a> </li> <li> <a href="probe.html">documents/probe</a> </li> <li> <a href="schema_.html">documents/schema</a> </li> <li> <a href="collector.html">ink/collector</a> </li> <li> <a href="bussable_.html">mixins/bussable</a> </li> <li> <a href="signalable_.html">mixins/signalable</a> </li> <li> <a href="format.html">strings/format</a> </li> <li> <a href="logger.html">utils/logger</a> </li> </ul> </li> <li class="dropdown"> <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a> <ul class="dropdown-menu "> <li> <a href="base.html">base</a> </li> <li> <a href="chains.html">base/chains</a> </li> <li> <a href="model.html">documents/model</a> </li> <li> <a href="probe.queryOperators.html">queryOperators</a> </li> <li> <a href="probe.updateOperators.html">updateOperators</a> </li> <li> <a href="collector-ACollector.html">ACollector</a> </li> <li> <a href="collector-CollectorBase_.html">CollectorBase</a> </li> <li> <a href="collector-OCollector.html">OCollector</a> </li> <li> <a href="signalable-Signal.html">Signal</a> </li> <li> <a href="logger.Logger.html">Logger</a> </li> </ul> </li> <li class="dropdown"> <a href="mixins.list.html" class="dropdown-toggle" data-toggle="dropdown">Mixins<b class="caret"></b></a> <ul class="dropdown-menu "> <li> <a href="schema.html">documents/schema</a> </li> <li> <a href="bussable.html">mixins/bussable</a> </li> <li> <a href="signalable.html">mixins/signalable</a> </li> </ul> </li> <li class="dropdown"> <a href="tutorials.list.html" class="dropdown-toggle" data-toggle="dropdown">Tutorials<b class="caret"></b></a> <ul class="dropdown-menu "> <li> <a href="tutorial-Teeth.html">Brush Teeth</a> </li> <li> <a href="tutorial-Car.html">Drive Car</a> </li> <li> <a href="tutorial-Test.html">Fence Test</a> </li> </ul> </li> <li class="dropdown"> <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a> <ul class="dropdown-menu "> <li> <a href="global.html#utils/logger">utils/logger</a> </li> </ul> </li> </ul> </div> </div> <div class="row-fluid"> <div class="span8"> <div id="main"> <h1 class="page-title">Mixin: documents/schema</h1> <section> <header> <h2> documents/schema </h2> </header> <article> <div class="container-overview"> <div class="description"><p>The validator mixin provides access to the features of the JSON validation system</p></div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-17">line 17</a> </li> </ul> </dd> </dl> </div> <h3 class="subsection-title">Members</h3> <dl> <dt> <h4 class="name" id="_defaultSchemaName"><span class="type-signature"></span>_defaultSchemaName<span class="type-signature"> :string|function</span></h4> </dt> <dd> <div class="description"> <p>The default name of the scheman when you use anonymous schemas. You can define this at the prototype for classified schemas. The can also</p> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">string</span> | <span class="param-type">function</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-44">line 44</a> </li> </ul> </dd> </dl> </dd> <dt> <h4 class="name" id="schema"><span class="type-signature"></span>schema<span class="type-signature"> :object</span></h4> </dt> <dd> <div class="description"> <p>The schema that defines the validation rules. This should probably be defined at the prototype for each object or model classification. It can be an anonymous schema defined right here, or this can be registered schema names to use, or just a single name</p> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">object</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-19">line 19</a> </li> </ul> </dd> </dl> </dd> <dt> <h4 class="name" id="schemas"><span class="type-signature"></span>schemas<span class="type-signature"> :object</span></h4> </dt> <dd> <div class="description"> <p>If you want to register multiple schemas, use this property instead</p> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">object</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-29">line 29</a> </li> </ul> </dd> </dl> </dd> <dt> <h4 class="name" id="validationOptions"><span class="type-signature"></span>validationOptions<span class="type-signature"> :object|function</span></h4> </dt> <dd> <div class="description"> <p>The options to pass to the validator when it runs</p> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">object</span> | <span class="param-type">function</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-54">line 54</a> </li> </ul> </dd> </dl> </dd> </dl> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="addCheck"><span class="type-signature"></span>addCheck<span class="signature">(name, formatter)</span><span class="type-signature"> &rarr; {boolean}</span></h4> </dt> <dd> <div class="description"> <p>It is possible to add support for custom checks (i.e., minItems, maxItems, minLength, maxLength, etc.) through the addCheck function</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <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 check</p></td> </tr> <tr> <td class="name"><code>formatter</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>Perform the check</p> <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>The value to check followed by any parameters from the schema</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-165">line 165</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </dd> <dt> <h4 class="name" id="addFormat"><span class="type-signature"></span>addFormat<span class="signature">(name, formatter)</span><span class="type-signature"> &rarr; {boolean}</span></h4> </dt> <dd> <div class="description"> <p>It is also possible to add support for additional string formats through the addFormat function.</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <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 formatter</p></td> </tr> <tr> <td class="name"><code>formatter</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>How to format it</p> <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>The value to format</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-153">line 153</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </dd> <dt> <h4 class="name" id="addType"><span class="type-signature"></span>addType<span class="signature">(name, operation)</span><span class="type-signature"> &rarr; {boolean}</span></h4> </dt> <dd> <div class="description"> <p>Create a type to be used in your schemas to define new validators</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <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 type</p></td> </tr> <tr> <td class="name"><code>operation</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>What to do with the type.</p> <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>The value to validation</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-141">line 141</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </dd> <dt> <h4 class="name" id="addTypeCoercion"><span class="type-signature"></span>addTypeCoercion<span class="signature">(name, coercer)</span><span class="type-signature"> &rarr; {boolean}</span></h4> </dt> <dd> <div class="description"> <p>Custom coercion rules</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <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 coercion</p></td> </tr> <tr> <td class="name"><code>coercer</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>Perform the coercion</p> <h6>Properties</h6> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>The value to coerce</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-177">line 177</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </dd> <dt> <h4 class="name" id="defaultDoc"><span class="type-signature"></span>defaultDoc<span class="signature">(schema)</span><span class="type-signature"> &rarr; {object}</span></h4> </dt> <dd> <div class="description"> <p>Builds a default document based on the schema. What this does is create a document from schema and for each property that has a default value or is required, the resultant object will contain that property. It is useful for extending values from some source that may be incomplete, like options or some such.</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>schema</code></td> <td class="type"> <span class="param-type">json-schema</span> </td> <td class="description last"><p>A schema to use to create the default document</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-239">line 239</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> </dd> <dt> <h4 class="name" id="extract"><span class="type-signature"></span>extract<span class="signature">(<span class="optional">record</span>, <span class="optional">schema</span>)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> <p>Extracts only the elements of the object that are defined in the schema</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>record</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>The record to extract from</p></td> </tr> <tr> <td class="name"><code>schema</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>The name of the schema to attach</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-122">line 122</a> </li> </ul> </dd> </dl> </dd> <dt> <h4 class="name" id="getSchema"><span class="type-signature"></span>getSchema<span class="signature">(<span class="optional">schemaName</span>)</span><span class="type-signature"> &rarr; {object}</span></h4> </dt> <dd> <div class="description"> <p>Get a registered schema by name</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>schemaName</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-190">line 190</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> </dd> <dt> <h4 class="name" id="registerSchemas"><span class="type-signature"></span>registerSchemas<span class="signature">(schemas)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> <p>Initialize the schema collection by registering the with the handler. You can call this at any time and as often as you like. It will be called once by the constructor on any instance schemas</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>schemas</code></td> <td class="type"> <span class="param-type">hash</span> </td> <td class="description last"><p>A hash of schemas where the key is the name of the schema</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-101">line 101</a> </li> </ul> </dd> </dl> </dd> <dt> <h4 class="name" id="validate"><span class="type-signature"></span>validate<span class="signature">(<span class="optional">record</span>, schemaName, <span class="optional">options</span>)</span><span class="type-signature"> &rarr; {object}</span></h4> </dt> <dd> <div class="description"> <p>Validate an object against the schema</p> </div> <h5>Parameters:</h5> <table class="params table table-striped"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>record</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>The record to validate</p></td> </tr> <tr> <td class="name"><code>schemaName</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">object</span> </td> <td class="attributes"> </td> <td class="description last"><p>The name of a previously registered schema</p></td> </tr> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>Options to pass to the validator</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"> <ul class="dummy"> <li> <a href="schema.js.html">documents/schema.js</a>, <a href="schema.js.html#sunlight-1-line-62">line 62</a> </li> </ul> </dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h5>Example</h5> <pre class="sunlight-highlight-javascript">&#x2F;&#x2F; This supports these signatures: instance.validate(record, schemaName, options); instance.validate(); &#x2F;&#x2F; this, this._defaultSchemaName, this.validationOptions instance.validate(record); &#x2F;&#x2F; record, this._defaultSchemaName, this.validationOptions instance.validate(schemaName); &#x2F;&#x2F;this, schemaName, this.validationOptions instance.validate(record, schemaName); &#x2F;&#x2F;record, schemaName, this.validationOptions instance.validate(schemaName, options); &#x2F;&#x2F;this, schemaName, this.validationOptions</pre> </dd> </dl> </article> </section> </div> <div class="clearfix"></div> <footer> <span class="copyright"> DocStrap Copyright © 2012-2013 The contributors to the JSDoc3 and DocStrap projects. </span> <br /> <span class="jsdoc-message"> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha5</a> on Sun Jun 1st 2014 using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>. </span> </footer> </div> <div class="span3"> <div id="toc"></div> </div> <br clear="both"> </div> </div> <!--<script src="scripts/sunlight.js"></script>--> <script src="scripts/docstrap.lib.js"></script> <script src="scripts/bootstrap-dropdown.js"></script> <script src="scripts/toc.js"></script> <script> $( function () { $( "#toc" ).toc( { anchorName : function ( i, heading, prefix ) { return $( heading ).attr( "id" ) || ( prefix + i ); }, selectors : "h1,h2,h3,h4", showAndHide : false, scrollTo : 60 } ); $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" ); $( "#main span[id^='toc']" ).addClass( "toc-shim" ); // $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" ); $( ".tutorial-section pre, .readme-section pre" ).each( function () { var $this = $( this ); var example = $this.find("code" ); exampleText = example.html(); var lang = /{@lang (.*?)}/.exec( exampleText ); if ( lang && lang[1] ) { exampleText = exampleText.replace( lang[0], "" ); example.html(exampleText); lang = lang[1]; } else { lang = "javascript"; } if ( lang ) { $this .addClass( "sunlight-highlight-" + lang ) .addClass( "linenums" ) .html( example.html() ); } } ); Sunlight.highlightAll( { lineNumbers : true, showMenu:true, enableDoclinks:true } ); } ); </script> <!--Google Analytics--> <!--Navigation and Symbol Display--> </body> </html>