jsdoc-oblivion
Version:
A gray and blue theme for JSDoc.
2,409 lines (849 loc) • 33.3 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=yes, width=device-width">
<title>Oblivion — Mixin: documents/schema</title>
<link rel="shortcut icon" href="/favicon.ico">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.dark.css">
<link type="text/css" rel="stylesheet" href="styles/site.oblivion.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">Oblivion</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">documents/probe.queryOperators</a>
</li>
<li>
<a href="probe.updateOperators.html">documents/probe.updateOperators</a>
</li>
<li>
<a href="collector-ACollector.html">ink/collector~ACollector</a>
</li>
<li>
<a href="collector-CollectorBase_.html">ink/collector~CollectorBase</a>
</li>
<li>
<a href="collector-OCollector.html">ink/collector~OCollector</a>
</li>
<li>
<a href="signalable-Signal.html">mixins/signalable~Signal</a>
</li>
<li>
<a href="logger.Logger.html">utils/logger.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>
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span3">
<div id="toc"></div>
</div>
<div class="span9">
<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">The validator mixin provides access to the features of the JSON validation system</div>
<dl class="details">
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<dl>
<dt class="name" id="_defaultSchemaName">
<h4><span class="type-signature"></span>_defaultSchemaName<span class="type-signature"> :string|function</span></h4>
</dt>
<dd>
<div class="description">
The default name of the scheman when you use anonymous schemas. You can define this at the prototype for classified
schemas. The can also
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
|
<span class="param-type">function</span>
</li>
</ul>
<dl class="details">
</dl>
</dd>
<dt class="name" id="schema">
<h4><span class="type-signature"></span>schema<span class="type-signature"> :object</span></h4>
</dt>
<dd>
<div class="description">
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
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">object</span>
</li>
</ul>
<dl class="details">
</dl>
</dd>
<dt class="name" id="schemas">
<h4><span class="type-signature"></span>schemas<span class="type-signature"> :object</span></h4>
</dt>
<dd>
<div class="description">
If you want to register multiple schemas, use this property instead
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">object</span>
</li>
</ul>
<dl class="details">
</dl>
</dd>
<dt class="name" id="validationOptions">
<h4><span class="type-signature"></span>validationOptions<span class="type-signature"> :object|function</span></h4>
</dt>
<dd>
<div class="description">
The options to pass to the validator when it runs
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">object</span>
|
<span class="param-type">function</span>
</li>
</ul>
<dl class="details">
</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"> → {boolean}</span></h4>
</dt>
<dd>
<div class="description">
It is possible to add support for custom checks (i.e., minItems, maxItems, minLength, maxLength, etc.) through the addCheck function
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">The name of the check</td>
</tr>
<tr>
<td class="name"><code>formatter</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">Perform the check
<h6>Properties</h6>
<div class="params-table-container">
<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">The value to check followed by any parameters from the schema</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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"> → {boolean}</span></h4>
</dt>
<dd>
<div class="description">
It is also possible to add support for additional string formats through the addFormat function.
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">The name of the formatter</td>
</tr>
<tr>
<td class="name"><code>formatter</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">How to format it
<h6>Properties</h6>
<div class="params-table-container">
<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">The value to format</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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"> → {boolean}</span></h4>
</dt>
<dd>
<div class="description">
Create a type to be used in your schemas to define new validators
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">The name of the type</td>
</tr>
<tr>
<td class="name"><code>operation</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">What to do with the type.
<h6>Properties</h6>
<div class="params-table-container">
<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">The value to validation</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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"> → {boolean}</span></h4>
</dt>
<dd>
<div class="description">
Custom coercion rules
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">The name of the coercion</td>
</tr>
<tr>
<td class="name"><code>coercer</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">Perform the coercion
<h6>Properties</h6>
<div class="params-table-container">
<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">The value to coerce</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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"> → {object}</span></h4>
</dt>
<dd>
<div class="description">
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.
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">A schema to use to create the default document</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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">
Extracts only the elements of the object that are defined in the schema
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">
<optional><br>
</td>
<td class="description last">The record to extract from</td>
</tr>
<tr>
<td class="name"><code>schema</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The name of the schema to attach</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</dl>
</dd>
<dt>
<h4 class="name" id="extract"><span class="type-signature"></span>extract<span class="signature">(<span class="optional">schema</span>, <span class="optional">src</span>)</span><span class="type-signature"> → {object}</span></h4>
</dt>
<dd>
<div class="description">
This method will create a new object that contains only the fields and no methods or other artifacts. This is useful
for creating objects to pass over the wire or save in a table. This is not deeply copied, so changes made to the
extracted object will be represented in this class for reference objects.
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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>schema</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The schema name to use</td>
</tr>
<tr>
<td class="name"><code>src</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The object to extract fields from</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Data-only version of the class instance.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</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"> → {object}</span></h4>
</dt>
<dd>
<div class="description">
Get a registered schema by name
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">
<optional><br>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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">
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
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">A hash of schemas where the key is the name of the schema</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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"> → {object}</span></h4>
</dt>
<dd>
<div class="description">
Validate an object against the schema
</div>
<h5>Parameters:</h5>
<div class="params-table-container">
<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">
<optional><br>
</td>
<td class="description last">The record to validate</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">The name of a previously registered schema</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Options to pass to the validator</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</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">// This supports these signatures:
instance.validate(record, schemaName, options);
instance.validate(); // this, this._defaultSchemaName, this.validationOptions
instance.validate(record); // record, this._defaultSchemaName, this.validationOptions
instance.validate(schemaName); //this, schemaName, this.validationOptions
instance.validate(record, schemaName); //record, schemaName, this.validationOptions
instance.validate(schemaName, options); //this, schemaName, this.validationOptions</pre>
</dd>
</dl>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
Copyright © 2014 <a href='http://moogs.io' target='_blank'>Moogs, LLC.</a>
</span>
<br />
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc" target="_blank">JSDoc 3.3.0-alpha9</a>
on 2014-09-07T09:05:23-07:00
</span>
</footer>
</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 () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : "100px"
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
// $( ".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>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
</body>
</html>