quanstructor
Advanced tools
Comparing version 0.4.8 to 0.4.9
{ | ||
"name": "quanstructor", | ||
"version": "0.4.8", | ||
"version": "0.4.9", | ||
"description": "Exceptionally powerful object model builder for complex architectures", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"isa.js": "^2.2.12", | ||
"vindication.js": "^4.20.1" | ||
"vindication.js": "^4.20.4" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": {}, |
@@ -12,2 +12,4 @@ let { defined } = require('./lib/Statics') | ||
const SEPARATOR = ',' | ||
const PRIMUS = 'PRIMUS' | ||
@@ -66,2 +68,7 @@ | ||
}, | ||
_findQ ( qRef, obj = {} ) { | ||
let refs = qRef.split( SEPARATOR ).map( (ref) => { return ref.trim() } ).filter( (ref) => { return ref } ) | ||
if ( refs.length < 2 ) return qRef | ||
return obj._qtype || refs[0] | ||
}, | ||
_tune () { | ||
@@ -123,20 +130,22 @@ let self = this | ||
validate ( obj ) { | ||
for (let prop in obj) { | ||
if ( !this.specs[ prop ] ) continue | ||
if ( this.specs[ prop ].Proxy ) continue | ||
let self = this | ||
for (let prop in self.specs) { | ||
if ( self.specs[ prop ].Proxy ) continue | ||
if ( this.specs[ prop ].Quanstructor && obj[ prop ] ) { | ||
if ( self.specs[ prop ].Quanstructor && obj[ prop ] ) { | ||
_.isArray( obj[ prop ] ) | ||
? obj[ prop ].map( (item) => { return QUANSTRUCTORS[ this.specs[ prop ].Quanstructor ].validate( item ) } ) | ||
: QUANSTRUCTORS[ this.specs[ prop ].Quanstructor ].validate( obj[prop] ) | ||
? obj[ prop ].map( (item) => { | ||
return QUANSTRUCTORS[ self._findQ( self.specs[ prop ].Quanstructor, item ) ].validate( item ) | ||
} ) | ||
: QUANSTRUCTORS[ self._findQ( self.specs[ prop ].Quanstructor, obj[prop]) ].validate( obj[prop] ) | ||
} | ||
if ( !this.specs[ prop ].validation ) continue | ||
if ( !self.specs[ prop ].validation ) continue | ||
let constraint = {} | ||
constraint[ prop ] = this.specs[ prop ].validation | ||
constraint[ prop ] = self.specs[ prop ].validation | ||
let res = v.validate( obj, constraint ) | ||
// let res = v.validate( obj[prop], this.specs[ prop ].validation ) | ||
if (res && Object.keys(res).length > 0 ) | ||
throw BaseErrors.FailedSchemaValidation( { schema: this.name, property: prop, validation: JSON.stringify(res) } ) | ||
throw BaseErrors.FailedSchemaValidation( { schema: self.name, property: prop, validation: JSON.stringify(res) } ) | ||
} | ||
@@ -164,11 +173,13 @@ return obj | ||
let res = { } | ||
for (let attrib of this.attributes) { | ||
if ( this.specs[ attrib ].Proxy ) continue | ||
for (let attrib of self.attributes) { | ||
if ( self.specs[ attrib ].Proxy ) continue | ||
if ( this.specs[ attrib ].Quanstructor ) { | ||
if ( self.specs[ attrib ].Quanstructor ) { | ||
res[ attrib ] = !obj[ attrib ] | ||
? ( _.isArray( self.specs[ attrib ].default ) ? [] : await QUANSTRUCTORS[ self.specs[ attrib ].Quanstructor ].proto( projection, options ) ) | ||
? ( _.isArray( self.specs[ attrib ].default ) ? [] : await QUANSTRUCTORS[ self._findQ( self.specs[ attrib ].Quanstructor ) ].proto( projection, options ) ) | ||
: (_.isArray( obj[ attrib ] ) ? await Promise.all( | ||
obj[ attrib ].map( (item) => { return QUANSTRUCTORS[ self.specs[ attrib ].Quanstructor ].build( item, projection, options ) } ) | ||
) : await QUANSTRUCTORS[ self.specs[ attrib ].Quanstructor ].build( obj[ attrib ], projection, options )) | ||
obj[ attrib ].map( (item) => { | ||
return QUANSTRUCTORS[ self._findQ( self.specs[ attrib ].Quanstructor, item ) ].build( item, projection, options ) | ||
} ) | ||
) : await QUANSTRUCTORS[ self._findQ( self.specs[ attrib ].Quanstructor, obj[ attrib ] ) ].build( obj[ attrib ], projection, options )) | ||
} else { | ||
@@ -201,2 +212,3 @@ let value = obj[attrib] || ( self.specs[ attrib ].hasOwnProperty('default') ? (_.isFunction( self.specs[ attrib ].default ) ? self.specs[ attrib ].default() : self.assigner.cloneObject( self.specs[ attrib ].default )) : v.defaultValue( self.specs[ attrib ].validation ) ) | ||
let proxified = self.Proxifier( res ) | ||
proxified._qtype = this.name | ||
return proxified | ||
@@ -220,14 +232,15 @@ }, | ||
let self = this | ||
let res = {} | ||
for (let space of this.projections[ projection ] ) { | ||
for (let space of self.projections[ projection ] ) { | ||
if ( space && !res[ space ] ) res[ space ] = {} | ||
let ref = !space ? res : res[ space ] | ||
for (let attrib of this.views[ space ] ) { | ||
let value = this.specs[ attrib ].hasOwnProperty('default') ? (_.isFunction(this.specs[ attrib ].default) ? this.specs[ attrib ].default() : this.specs[ attrib ].default) : v.defaultValue( this.specs[ attrib ].validation ) | ||
if ( this.specs[ attrib ].Quanstructor ) { | ||
for (let attrib of self.views[ space ] ) { | ||
let value = self.specs[ attrib ].hasOwnProperty('default') ? (_.isFunction(self.specs[ attrib ].default) ? self.specs[ attrib ].default() : self.specs[ attrib ].default) : v.defaultValue( this.specs[ attrib ].validation ) | ||
if ( self.specs[ attrib ].Quanstructor ) { | ||
res[ attrib ] = _.isArray( value ) | ||
? (options.foldArray ? [] : [ await QUANSTRUCTORS[ this.specs[ attrib ].Quanstructor ].proto( projection, options ) ]) | ||
: await QUANSTRUCTORS[ this.specs[ attrib ].Quanstructor ].proto( projection, options ) | ||
? (options.foldArray ? [] : [ await QUANSTRUCTORS[ self._findQ( this.specs[ attrib ].Quanstructor ) ].proto( projection, options ) ]) | ||
: await QUANSTRUCTORS[ self._findQ( self.specs[ attrib ].Quanstructor ) ].proto( projection, options ) | ||
} else { | ||
if ( this.specs[ attrib ]._allowNull || defined(value) ) | ||
if ( self.specs[ attrib ]._allowNull || defined(value) ) | ||
ref[ attrib ] = value | ||
@@ -251,19 +264,20 @@ } | ||
let self = this | ||
let res = {} | ||
for (let space of this.projections[ projection ] ) { | ||
for (let space of self.projections[ projection ] ) { | ||
if ( space && !res[ space ] ) res[ space ] = {} | ||
let ref = !space ? res : res[ space ] | ||
for (let attrib of this.views[ space ] ) { | ||
if ( !this._viewProxy && this.specs[ attrib ].Proxy && !this.specs[ attrib ]._viewProxy ) continue | ||
for (let attrib of self.views[ space ] ) { | ||
if ( !self._viewProxy && self.specs[ attrib ].Proxy && !self.specs[ attrib ]._viewProxy ) continue | ||
let value = this.specs[attrib].convert ? await this.specs[attrib].convert( obj[ attrib ] ) : obj[ attrib ] | ||
let value = self.specs[attrib].convert ? await self.specs[attrib].convert( obj[ attrib ] ) : obj[ attrib ] | ||
if ( this.specs[ attrib ].Quanstructor ) { | ||
if ( self.specs[ attrib ].Quanstructor ) { | ||
ref[ attrib ] = _.isArray( value ) | ||
? await Promise.all( | ||
value.map( (element) => { return QUANSTRUCTORS[ this.specs[ attrib ].Quanstructor ].viewAs( element, projection, options ) } ) | ||
) : await QUANSTRUCTORS[ this.specs[ attrib ].Quanstructor ].viewAs( value, projection, options ) | ||
value.map( (element) => { return QUANSTRUCTORS[ self._findQ( self.specs[ attrib ].Quanstructor, element ) ].viewAs( element, projection, options ) } ) | ||
) : await QUANSTRUCTORS[ self._findQ( self.specs[ attrib ].Quanstructor, value) ].viewAs( value, projection, options ) | ||
} | ||
else { | ||
if ( this.specs[ attrib ]._allowNull || defined(value) ) | ||
if ( self.specs[ attrib ]._allowNull || defined(value) ) | ||
ref[ attrib ] = value | ||
@@ -287,2 +301,3 @@ } | ||
module.exports = { | ||
SEPARATOR, | ||
QUALITY_SPACE, | ||
@@ -289,0 +304,0 @@ DEFINITIONS, |
@@ -79,2 +79,20 @@ const Quastructor = require( '../Quanstructor' ) | ||
} ) | ||
it('Crossroads', async function () { | ||
let RoadAbsoluter = Quastructor.newQuanstructor( 'Road', { | ||
distance: { validation: { required: true, typeof: Number } } | ||
} ) | ||
let HighwayAbsoluter = Quastructor.newQuanstructor( 'Highway', { | ||
lanes: { validation: { required: true, typeof: Number } } | ||
} ) | ||
let PathAbsoluter = Quastructor.newQuanstructor( 'Path', { | ||
ways: { default: [], Quanstructor: 'Road, Highway' } | ||
} ) | ||
console.log( JSON.stringify( await PathAbsoluter.build( { | ||
ways: [ { distance: 2 }, { lanes: 5, _qtype: 'Highway' } ] | ||
} ), null, 4 ) ) | ||
console.log( JSON.stringify( await PathAbsoluter.derive( { | ||
ways: [ { distance: 2 }, { lanes: 5, _qtype: 'Highway' } ] | ||
} ), null, 4 ) ) | ||
} ) | ||
} ) | ||
@@ -81,0 +99,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21008
568
Updatedvindication.js@^4.20.4