UNPKG

copious-transitions

Version:
184 lines (151 loc) 9.98 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: lib/general_validator.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: lib/general_validator.js</h1> <section> <article> <pre class="prettyprint source linenums"><code> const FieldValidatorTools = require('./field-validator-tools') /** * Provide the operations necessary to do field validation. * * This is a descendant of FieldValidatorTools and makes use of the method `setup_field_test`, when getting set up. * The `setup` method is called from the `intialize` method, called by the user processing clients. * * Initialization attempts to take as much as it can from the configuration to set up the tests that fields will have to * pass in order that a request may proceed. It takes test information from the configuration field `field_set`, which is a * map of form identifers to objects containing fields belonging to the forms. Each field maps to a field descriptor. * * * The method `valid` is called by the 'contractual' code when new requests come in to the contractual processing. * * * * * * * @extends FieldValidatorTools * @memberof field_validators */ class GeneralValidator extends FieldValidatorTools { constructor() { super() this.db = null this.sessions = null this.self = null this.field_set = {} // all form fields by form } /** * Sets up the validators that will look for particular fields belonging to a query object. * * The field set */ setup_tests() { let all_fields = this.field_set delete all_fields.reason // should be a text comment for ( let form_key in all_fields ) { let form = all_fields[form_key] for ( let field in form ) { let fieldDescriptor = form[field] super.setup_field_test(form_key,field,fieldDescriptor) } } } /** * Takes in the configuration data necessary to intialize the `application_tests` table in the super (FieldValidatorTools). * Calls `setup_tests`. * * @param {object} conf_obj * @param {object} db * @param {object} sessions */ initialize(conf_obj,db,sessions) { // this.db = db this.sessions = sessions // if ( conf_obj.field_set ) { // first the configuration object this.field_set = clonify(conf_obj.field_set) } // if ( this.self ) { // second programmed and DB acces this.self.prepare_tests() // the application adds to the *field_set* first provided by the configuration } this.setup_tests() } // /** * The list of fields will be from the `field_set` of this class. * The fields will be picked out by the name of a transition or operation. * If the list has not been defined by configuration, then this method will default to returning true, passing * the validation of data entries (format, syntax, simple semantics). * * First, if the `field` parameter is a string, this method searches for the fields object matching the key. * Given, the parameters is a string and is not in the `field_set`, this method will search in the local database for * the field object. * * If either the fields were pasts as an object or a search proved successful in finding it, the form data of the * object, `post_body`, will be examined using the previously configured tests in the ``application_tests` table. * * @param {object} post_body * @param {object|string} fields - either a key to a list of a list. * @returns {boolean} */ valid(post_body,fields) { // a particular set of fields for a form // if ( fields === undefined ) return(true) // if ( typeof fields === "string" ) { // first make sure that a field object is given let fields_key = fields fields = this.field_set[fields_key] if ( fields === undefined ) { fields = this.db.fetch_fields(fields_key) // if ( fields !== undefined) { // add it into our local field cache this.field_set[fields_key] = fields // a dynamic update, but may have to be pruned at some time. } } } // let form = post_body.form_key ? post_body.form_key : '' for ( let field in fields ) { // now the post body should have keys to data fields let field_info = post_body[field] if ( field &amp;&amp; field_info ) { let ftest = super.get_field_test(form,field) if ( ftest ) { if ( !ftest.test(post_body[field],ftest.parameters) ) return(false) } } else { return false } } return true } } module.exports = GeneralValidator </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="Contractual.html">Contractual</a></li><li><a href="CopiousTransitions.html">CopiousTransitions</a></li><li><a href="DefaultDB.html">DefaultDB</a></li><li><a href="base.html">base</a></li><li><a href="field_validators.html">field_validators</a></li></ul><h3>Classes</h3><ul><li><a href="Contractual.LocalTObjectCache.html">LocalTObjectCache</a></li><li><a href="Contractual.MimeHandling.html">MimeHandling</a></li><li><a href="Contractual.TransitionHandling.html">TransitionHandling</a></li><li><a href="Contractual.UserHandling.html">UserHandling</a></li><li><a href="CopiousTransitions.CopiousTransitions.html">CopiousTransitions</a></li><li><a href="DefaultDB.CustomizationMethodsByApplication.html">CustomizationMethodsByApplication</a></li><li><a href="DefaultDB.FauxInMemStore.html">FauxInMemStore</a></li><li><a href="DefaultDB.FileMapper.html">FileMapper</a></li><li><a href="DefaultDB.FilesAndRelays.html">FilesAndRelays</a></li><li><a href="DefaultDB.FilesAndRelays_base.html">FilesAndRelays_base</a></li><li><a href="DefaultDB.LocalStaticDB.html">LocalStaticDB</a></li><li><a href="DefaultDB.LocalStorageLifeCycle.html">LocalStorageLifeCycle</a></li><li><a href="DefaultDB.LocalStorageSerialization.html">LocalStorageSerialization</a></li><li><a href="DefaultDB.PageableMemStoreElement.html">PageableMemStoreElement</a></li><li><a href="DefaultDB.PersistenceContracts.html">PersistenceContracts</a></li><li><a href="DefaultDB.RemoteMessaging.html">RemoteMessaging</a></li><li><a href="DefaultDB.StaticDBDefault.html">StaticDBDefault</a></li><li><a href="GeneralUserDBWrapperImpl.html">GeneralUserDBWrapperImpl</a></li><li><a href="SessionTokenManager.html">SessionTokenManager</a></li><li><a href="base.DBClass.html">DBClass</a></li><li><a href="base.EndpointManager.html">EndpointManager</a></li><li><a href="base.GeneralAppLifeCycle.html">GeneralAppLifeCycle</a></li><li><a href="base.GeneralAuth.html">GeneralAuth</a></li><li><a href="base.GeneralBusiness.html">GeneralBusiness</a></li><li><a href="base.GeneralDynamic.html">GeneralDynamic</a></li><li><a href="base.GeneralMiddleWare.html">GeneralMiddleWare</a></li><li><a href="base.GeneralStatic.html">GeneralStatic</a></li><li><a href="base.GeneralTransitionEngImpl.html">GeneralTransitionEngImpl</a></li><li><a href="base.SessionManager.html">SessionManager</a></li><li><a href="base.SessionManager_Lite.html">SessionManager_Lite</a></li><li><a href="base.TaggedTransition.html">TaggedTransition</a></li><li><a href="base.TokenTables.html">TokenTables</a></li><li><a href="base.UserMessageEndpoint.html">UserMessageEndpoint</a></li><li><a href="base.WebSocketManager.html">WebSocketManager</a></li><li><a href="field_validators.DataLookupField.html">DataLookupField</a></li><li><a href="field_validators.EmailField.html">EmailField</a></li><li><a href="field_validators.EmailVerifyField.html">EmailVerifyField</a></li><li><a href="field_validators.FieldTest.html">FieldTest</a></li><li><a href="field_validators.FieldValidatorTools.html">FieldValidatorTools</a></li><li><a href="field_validators.ForeignAuth.html">ForeignAuth</a></li><li><a href="field_validators.GeneralValidator.html">GeneralValidator</a></li><li><a href="field_validators.LengthyAlphabetField.html">LengthyAlphabetField</a></li><li><a href="field_validators.LengthyDigitalField.html">LengthyDigitalField</a></li><li><a href="field_validators.LengthyField.html">LengthyField</a></li><li><a href="field_validators.LengthyStringField.html">LengthyStringField</a></li><li><a href="field_validators.PasswordField.html">PasswordField</a></li><li><a href="field_validators.PasswordVerifyField.html">PasswordVerifyField</a></li><li><a href="field_validators.TypeCheckField.html">TypeCheckField</a></li></ul><h3>Global</h3><ul><li><a href="global.html#generate_password_block">generate_password_block</a></li><li><a href="global.html#load_configuration">load_configuration</a></li><li><a href="global.html#load_parameters">load_parameters</a></li><li><a href="global.html#module_top">module_top</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Oct 31 2023 17:32:59 GMT-0700 (Pacific Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>