nl_tokens: / * Function that accept constraints in json format and will transform them into nano query for couchDB .
pl_tokens: function constraintsToQuery ( constraints , either = false ) { let constEmitter = new EventEmitter ; let query = { "selector" : { } } ; let strConstr = JSON . stringify ( constraints ) ; let sel = query . selector ; if ( strConstr === JSON . stringify ( { } ) || strConstr === JSON . stringify ( [ ] ) ) { let error = 'Empty constraints json or array given' ; logger_1 . logger . <mask> ( 'warn' , error ) ; constEmitter . emit ( 'errorOnConstraints' ) ; return constEmitter ; } // (1) if ( ! constraints ) { let error = 'Constraints value is evaluated to false, maybe empty object or empty string' ; logger_1 . logger . log ( 'warn' , error ) ; constEmitter . emit ( 'errorOnConstraints' ) ; return constEmitter ; } // (1) if ( either ) sel [ "$or" ] = [ ] ; // (2) Object . keys ( constraints ) . map ( elem => { if ( constraints [ elem ] === null ) { if ( ! either ) sel [ elem ] = { "$exists" : true } ; // (3.1) return ; // if constraints is null then we jump to the next iteration of the map => will return any value on this key } if ( types . isStringMap ( constraints [ elem ] ) ) { // (3.2) either ? sel . $or . push ( { [ elem ] : { "$in" : [ constraints [ elem ] ] } } ) : sel [ elem ] = { "$in" : [ constraints [ elem ] ] } ; } else { either ? sel . $or . push ( { [ elem ] : constraints [ elem ] } ) : sel [ elem ] = constraints [ elem ] ; } } ) ; logger_1 . logger . log ( 'debug' , 'query: ' + JSON . stringify ( query ) ) ; dbMod . testRequest ( query , nameDB , accountDB , passwordDB , addressDB , portDB , proxyBool ) . on ( 'requestDone' , ( data ) => { if ( ! data . docs . length ) { constEmitter . emit ( 'noDocsFound' , data ) ; } else { constEmitter . emit ( 'docsFound' , data ) ; } } ) . on ( 'requestError' , ( err ) => { constEmitter . emit ( 'errorOnConstraints' , err ) ; } ) ; return constEmitter ; }