@@ -309,7 +309,6 @@ WOQLQuery.prototype.unique = function(prefix, vari, type){
309309WOQLQuery . prototype . concat = function ( list , v ) {
310310 if ( typeof list == "string" ) {
311311 var nlist = list . split ( / ( v : [ \w _ ] + ) \b / ) ;
312- var nxlist = [ ] ;
313312 for ( var i = 1 ; i < nlist . length ; i ++ ) {
314313 if ( nlist [ i - 1 ] . substring ( nlist [ i - 1 ] . length - 1 ) == "v" && nlist [ i ] . substring ( 0 , 1 ) == ":" ) {
315314 nlist [ i - 1 ] = nlist [ i - 1 ] . substring ( 0 , nlist [ i - 1 ] . length - 1 ) ;
@@ -471,7 +470,13 @@ WOQLQuery.prototype.and = function (...queries) {
471470 this . cursor . and = [ ] ;
472471 for ( let i = 0 ; i < queries . length ; i ++ ) {
473472 if ( queries [ i ] . contains_update ) this . contains_update = true ;
474- this . cursor . and . push ( queries [ i ] . json ( ) ) ;
473+ var nquery = ( queries [ i ] . json ? queries [ i ] . json ( ) : queries [ i ] ) ;
474+ if ( nquery [ 'and' ] ) {
475+ this . cursor . and = this . cursor . and . concat ( nquery [ 'and' ] ) ;
476+ }
477+ else {
478+ this . cursor . and . push ( nquery ) ;
479+ }
475480 }
476481 return this ;
477482} ;
@@ -480,7 +485,8 @@ WOQLQuery.prototype.or = function (...queries) {
480485 this . cursor . or = [ ] ;
481486 for ( let i = 0 ; i < queries . length ; i ++ ) {
482487 if ( queries [ i ] . contains_update ) this . contains_update = true ;
483- this . cursor . or . push ( queries [ i ] . json ( ) ) ;
488+ var nquery = ( queries [ i ] . json ? queries [ i ] . json ( ) : queries [ i ] ) ;
489+ this . cursor . or . push ( nquery ) ;
484490 }
485491 return this ;
486492} ;
@@ -934,8 +940,8 @@ WOQLQuery.prototype.getDocumentConnections = function(id){
934940 WOQL . triple ( "v:Entid" , "type" , "v:Enttype" ) ,
935941 WOQL . sub ( "v:Enttype" , "tcs:Document" ) ,
936942 WOQL . or (
937- WOQL . triple ( "v:Docid" , "v:Outgoing" , "v:Entid" ) ,
938- WOQL . triple ( "v:Entid" , "v:Incoming" , "v:Docid" )
943+ WOQL . triple ( id , "v:Outgoing" , "v:Entid" ) ,
944+ WOQL . triple ( "v:Entid" , "v:Incoming" , id )
939945 ) ,
940946 WOQL . opt ( ) . triple ( "v:Entid" , "rdfs:label" , "v:Label" ) ,
941947 WOQL . opt ( ) . quad ( "v:Enttype" , "rdfs:label" , "v:Class_Label" , "db:schema" )
@@ -1332,7 +1338,9 @@ WOQLQuery.prototype.prettyPrint = function(indent, show_context, q, fluent){
13321338 }
13331339 else {
13341340 //non chainable operators all live inside the function call parameters
1335- str += this . uncleanArguments ( operator , val , indent , show_context ) ;
1341+ if ( ! this . hasShortcut ( operator , val , indent ) ) {
1342+ str += this . uncleanArguments ( operator , val , indent , show_context ) ;
1343+ }
13361344 }
13371345 }
13381346 //remove any trailing dots in the chain (only exist in incompletely specified queries)
@@ -1370,43 +1378,41 @@ WOQLQuery.prototype.isChainable = function(operator, lastArg){
13701378 * Transforms arguments to WOQL functions from the internal (clean) version, to the WOQL.js human-friendly version
13711379 */
13721380WOQLQuery . prototype . uncleanArguments = function ( operator , args , indent , show_context ) {
1373- str = '(' ;
1374- const args_take_newlines = [ "and" , "or" ] ;
13751381 if ( this . hasShortcut ( operator , args ) ) {
1376- return this . getShortcut ( args , indent ) ;
1382+ return this . getShortcut ( operator , args , indent ) ;
13771383 }
1378- else {
1379- for ( var i = 0 ; i < args . length ; i ++ ) {
1380- if ( this . argIsSubQuery ( operator , args [ i ] , i ) ) {
1381- str += this . prettyPrint ( indent + this . indent , show_context , args [ i ] , false ) ;
1382- }
1383- else if ( operator == "get" && i == 0 ) { // weird one, needs special casing
1384- str += "\n" + nspaces ( indent - this . indent ) + "WOQL" ;
1385- for ( var j = 0 ; j < args [ 0 ] . length ; j ++ ) {
1386- var myas = ( args [ 0 ] [ j ] . as ? args [ 0 ] [ j ] . as : args [ 0 ] [ j ] ) ;
1387- var lhs = myas [ 0 ] ;
1388- var rhs = myas [ 1 ] ;
1389- if ( typeof lhs == "object" && lhs [ '@value' ] ) {
1390- lhs = lhs [ '@value' ] ;
1391- }
1392- if ( typeof lhs == "object" ) {
1393- lhs = JSON . stringify ( lhs ) ;
1394- }
1395- else {
1396- lhs = '"' + lhs + '"'
1397- }
1398- str += '.as(' + lhs ;
1399- if ( rhs ) str += ', "' + rhs + '"' ;
1400- str += ")" ;
1401- str += "\n" + nspaces ( indent ) ;
1384+ let str = '(' ;
1385+ for ( var i = 0 ; i < args . length ; i ++ ) {
1386+ if ( this . argIsSubQuery ( operator , args [ i ] , i ) ) {
1387+ str += this . prettyPrint ( indent + this . indent , show_context , args [ i ] , false ) ;
1388+ }
1389+ else if ( operator == "get" && i == 0 ) { // weird one, needs special casing
1390+ str += "\n" + nspaces ( indent - this . indent ) + "WOQL" ;
1391+ for ( var j = 0 ; j < args [ 0 ] . length ; j ++ ) {
1392+ var myas = ( args [ 0 ] [ j ] . as ? args [ 0 ] [ j ] . as : args [ 0 ] [ j ] ) ;
1393+ var lhs = myas [ 0 ] ;
1394+ var rhs = myas [ 1 ] ;
1395+ if ( typeof lhs == "object" && lhs [ '@value' ] ) {
1396+ lhs = lhs [ '@value' ] ;
14021397 }
1398+ if ( typeof lhs == "object" ) {
1399+ lhs = JSON . stringify ( lhs ) ;
1400+ }
1401+ else {
1402+ lhs = '"' + lhs + '"'
1403+ }
1404+ str += '.as(' + lhs ;
1405+ if ( rhs ) str += ', "' + rhs + '"' ;
1406+ str += ")" ;
1407+ str += "\n" + nspaces ( indent ) ;
14031408 }
1404- else {
1405- str += this . uncleanArgument ( operator , args [ i ] , i , args ) ;
1406- }
1407- if ( i < args . length - 1 ) str += ',' ;
14081409 }
1410+ else {
1411+ str += this . uncleanArgument ( operator , args [ i ] , i , args ) ;
1412+ }
1413+ if ( i < args . length - 1 ) str += ',' ;
14091414 }
1415+ const args_take_newlines = [ "and" , "or" ] ;
14101416 if ( args_take_newlines . indexOf ( operator ) != - 1 ) {
14111417 str += "\n" + nspaces ( indent - this . indent ) ;
14121418 }
@@ -1519,11 +1525,12 @@ WOQLQuery.prototype.unclean = function(s, part){
15191525 return s ;
15201526}
15211527
1522- WOQLQuery . prototype . hasShortcut = function ( operator , args , indent , show_context ) {
1528+ WOQLQuery . prototype . hasShortcut = function ( operator , args , indent ) {
15231529 if ( operator == "true" ) return true ;
1530+ return false ;
15241531}
15251532
1526- WOQLQuery . prototype . getShortcut = function ( operator , args , indent , show_context ) {
1533+ WOQLQuery . prototype . getShortcut = function ( operator , args , indent ) {
15271534 if ( operator == "true" ) return true ;
15281535}
15291536
0 commit comments