@@ -391,148 +391,145 @@ WOQLQuery.prototype.put = function (asvars, query, query_resource) {
391391 * @param {...(array|string) } varList variable number of arguments
392392 * @returns WOQLQuery
393393 */
394- WOQLQuery . prototype . as = function ( ...varList ) {
395- //if (varList && varList[0] == 'args')
396- //return [['indexed_as_var', 'named_as_var']]
397- if ( ! Array . isArray ( this . query ) ) this . query = [ ]
398- if ( Array . isArray ( varList [ 0 ] ) ) {
399- if ( ! varList [ 1 ] ) {
400- //indexed as vars
401- for ( var i = 0 ; i < varList [ 0 ] . length ; i ++ ) {
402- let iasv = this . asv ( i , varList [ 0 ] [ i ] )
403- this . query . push ( iasv )
404- }
405- } else {
406- for ( var i = 0 ; i < varList . length ; i ++ ) {
407- let onemap = varList [ i ]
408- if ( Array . isArray ( onemap ) && onemap . length >= 2 ) {
409- let type = onemap && onemap . length > 2 ? onemap [ 2 ] : false
410- let oasv = this . asv ( onemap [ 0 ] , onemap [ 1 ] , type )
411- this . query . push ( oasv )
412- }
413- }
414- }
415- } else if ( typeof varList [ 0 ] == 'number' || typeof varList [ 0 ] == 'string' ) {
416- if ( varList [ 2 ] && typeof varList [ 2 ] == 'string' ) {
417- var oasv = this . asv ( varList [ 0 ] , varList [ 1 ] , varList [ 2 ] )
418- } else if ( varList [ 1 ] && typeof varList [ 1 ] == 'string' ) {
419- if ( varList [ 1 ] . substring ( 0 , 4 ) == 'xsd:' || varList [ 1 ] . substring ( 0 , 4 ) == 'xdd:' ) {
420- var oasv = this . asv ( this . query . length , varList [ 0 ] , varList [ 1 ] )
421- } else {
422- var oasv = this . asv ( varList [ 0 ] , varList [ 1 ] )
423- }
424- } else {
425- var oasv = this . asv ( this . query . length , varList [ 0 ] )
394+ WOQLQuery . prototype . as = function ( ...varList ) {
395+ // if (varList && varList[0] == 'args')
396+ // return [['indexed_as_var', 'named_as_var']]
397+ if ( ! Array . isArray ( this . query ) ) this . query = [ ] ;
398+ if ( Array . isArray ( varList [ 0 ] ) ) {
399+ if ( ! varList [ 1 ] ) {
400+ // indexed as vars
401+ for ( var i = 0 ; i < varList [ 0 ] . length ; i ++ ) {
402+ const iasv = this . asv ( i , varList [ 0 ] [ i ] ) ;
403+ this . query . push ( iasv ) ;
404+ }
405+ } else {
406+ for ( var i = 0 ; i < varList . length ; i ++ ) {
407+ const onemap = varList [ i ] ;
408+ if ( Array . isArray ( onemap ) && onemap . length >= 2 ) {
409+ const type = onemap && onemap . length > 2 ? onemap [ 2 ] : false ;
410+ const oasv = this . asv ( onemap [ 0 ] , onemap [ 1 ] , type ) ;
411+ this . query . push ( oasv ) ;
426412 }
427- this . query . push ( oasv )
428- } else if ( typeof varList [ 0 ] == 'object' ) {
429- //check if it is an class object with an json method
430- this . query . push ( varList [ 0 ] . json ? varList [ 0 ] . json ( ) : varList [ 0 ] )
413+ }
431414 }
432- return this
433- }
434-
435- WOQLQuery . prototype . file = function ( fpath , opts ) {
436- //if (fpath && fpath == 'args') return ['file', 'format']
437- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
438- this . cursor [ '@type' ] = 'QueryResource'
439- this . cursor [ 'source' ] = { '@type' : 'Source' , 'file' : fpath }
440- this . cursor [ 'format' ] = "csv" // hard coded for now
441- if ( typeof opts != 'undefined' )
442- this . cursor [ 'options' ] = opts
443- return this
444- }
445-
446- WOQLQuery . prototype . remote = function ( uri , opts ) {
447- //if (uri && uri == 'args') return ['remote_uri', 'format']
448- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
449- this . cursor [ '@type' ] = 'QueryResource'
450- this . cursor [ 'source' ] = { '@type' : 'Source' , 'url' : uri }
451- this . cursor [ 'format' ] = "csv" // hard coded for now
452- if ( typeof opts != 'undefined' )
453- this . cursor [ 'options' ] = opts
454- return this
455- }
456-
457- WOQLQuery . prototype . post = function ( fpath , opts , source = 'post' ) {
458- //if (fpath && fpath == 'args') return ['file', 'format']
459- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
460- this . cursor [ '@type' ] = 'QueryResource'
461- this . cursor [ 'source' ] = { '@type' : 'Source' , [ source ] : fpath }
462- this . cursor [ 'format' ] = "csv" // hard coded for now
463- this . cursor [ 'options' ] = opts
464- if ( typeof opts != 'undefined' )
465- this . cursor [ 'options' ] = opts
466- return this
467- }
468-
469- WOQLQuery . prototype . delete_triple = function ( Subject , Predicate , Object_or_Literal ) {
470- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
471- let args = this . triple ( Subject , Predicate , Object_or_Literal )
472- //if (Subject && Subject == 'args') return args
473- this . cursor [ '@type' ] = 'DeleteTriple'
474- return this . updated ( )
475- }
476-
477- WOQLQuery . prototype . add_triple = function ( Subject , Predicate , Object_or_Literal ) {
478- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
479- let args = this . triple ( Subject , Predicate , Object_or_Literal )
480- //if (Subject && Subject == 'args') return args
481- this . cursor [ '@type' ] = 'AddTriple'
482- return this . updated ( )
483- }
484-
485- WOQLQuery . prototype . delete_quad = function ( a , b , c , g ) {
486- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
487- let args = this . triple ( a , b , c )
488- //if (a && a == 'args') return args.concat(['graph'])
489- if ( ! g )
490- return this . parameterError (
491- 'Delete Quad takes four parameters, the last should be a graph id' ,
492- )
493- this . cursor [ '@type' ] = 'DeleteTriple'
494- this . cursor [ 'graph' ] = this . cleanGraph ( g )
495- return this . updated ( )
496- }
497-
498- WOQLQuery . prototype . add_quad = function ( a , b , c , g ) {
499- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
500- let args = this . triple ( a , b , c )
501- //if (a && a == 'args') return args.concat(['graph'])
502- if ( ! g )
503- return this . parameterError ( 'Add Quad takes four parameters, the last should be a graph id' )
504- this . cursor [ '@type' ] = 'AddTriple'
505- this . cursor [ 'graph' ] = this . cleanGraph ( g )
506- return this . updated ( )
507- }
508-
509- WOQLQuery . prototype . trim = function ( untrimmed , trimmed ) {
510- //if (untrimmed && untrimmed == 'args')
511- //return ['untrimmed', 'trimmed']
512- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
513- this . cursor [ '@type' ] = 'Trim'
514- this . cursor [ 'untrimmed' ] = this . cleanDataValue ( untrimmed )
515- this . cursor [ 'trimmed' ] = this . cleanDataValue ( trimmed )
516- return this
517- }
518-
519- WOQLQuery . prototype . eval = function ( arith , res ) {
520- //if (arith && arith == 'args')
521- //return ['expression', 'result']
522- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
523- this . cursor [ '@type' ] = 'Eval'
524- this . cursor [ 'expression' ] = arith . json ? arith . json ( ) : arith
525- this . cursor [ 'result' ] = this . cleanArithmeticValue ( res )
526- return this
527- }
528-
529- WOQLQuery . prototype . plus = function ( ...args ) {
530- //if (args && args[0] == 'args') return ['first', 'second']
531- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( )
532- this . cursor [ '@type' ] = 'Plus'
533- this . cursor [ 'left' ] = this . arop ( args . shift ( ) )
534- if ( args . length > 1 ) {
535- this . cursor [ 'right' ] = this . jobj ( new WOQLQuery ( ) . plus ( ...args ) )
415+ } else if ( typeof varList [ 0 ] === 'number' || typeof varList [ 0 ] === 'string' ) {
416+ if ( varList [ 2 ] && typeof varList [ 2 ] === 'string' ) {
417+ var oasv = this . asv ( varList [ 0 ] , varList [ 1 ] , varList [ 2 ] ) ;
418+ } else if ( varList [ 1 ] && typeof varList [ 1 ] === 'string' ) {
419+ if ( varList [ 1 ] . substring ( 0 , 4 ) === 'xsd:' || varList [ 1 ] . substring ( 0 , 4 ) === 'xdd:' ) {
420+ var oasv = this . asv ( this . query . length , varList [ 0 ] , varList [ 1 ] ) ;
421+ } else {
422+ var oasv = this . asv ( varList [ 0 ] , varList [ 1 ] ) ;
423+ }
424+ } else {
425+ var oasv = this . asv ( this . query . length , varList [ 0 ] ) ;
426+ }
427+ this . query . push ( oasv ) ;
428+ } else if ( typeof varList [ 0 ] === 'object' ) {
429+ // check if it is an class object with an json method
430+ this . query . push ( varList [ 0 ] . json ? varList [ 0 ] . json ( ) : varList [ 0 ] ) ;
431+ }
432+ return this ;
433+ } ;
434+
435+ WOQLQuery . prototype . file = function ( fpath , opts ) {
436+ // if (fpath && fpath == 'args') return ['file', 'format']
437+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
438+ this . cursor [ '@type' ] = 'QueryResource' ;
439+ this . cursor . source = { '@type' : 'Source' , file : fpath } ;
440+ this . cursor . format = 'csv' ; // hard coded for now
441+ if ( typeof opts !== 'undefined' ) this . cursor . options = opts ;
442+ return this ;
443+ } ;
444+
445+ WOQLQuery . prototype . remote = function ( uri , opts ) {
446+ // if (uri && uri == 'args') return ['remote_uri', 'format']
447+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
448+ this . cursor [ '@type' ] = 'QueryResource' ;
449+ this . cursor . source = { '@type' : 'Source' , url : uri } ;
450+ this . cursor . format = 'csv' ; // hard coded for now
451+ if ( typeof opts !== 'undefined' ) this . cursor . options = opts ;
452+ return this ;
453+ } ;
454+
455+ WOQLQuery . prototype . post = function ( fpath , opts , source = 'post' ) {
456+ // if (fpath && fpath == 'args') return ['file', 'format']
457+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
458+ this . cursor [ '@type' ] = 'QueryResource' ;
459+ this . cursor . source = { '@type' : 'Source' , [ source ] : fpath } ;
460+ this . cursor . format = 'csv' ; // hard coded for now
461+ this . cursor . options = opts ;
462+ if ( typeof opts !== 'undefined' ) this . cursor . options = opts ;
463+ return this ;
464+ } ;
465+
466+ WOQLQuery . prototype . delete_triple = function ( Subject , Predicate , Object_or_Literal ) {
467+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
468+ const args = this . triple ( Subject , Predicate , Object_or_Literal ) ;
469+ // if (Subject && Subject == 'args') return args
470+ this . cursor [ '@type' ] = 'DeleteTriple' ;
471+ return this . updated ( ) ;
472+ } ;
473+
474+ WOQLQuery . prototype . add_triple = function ( Subject , Predicate , Object_or_Literal ) {
475+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
476+ const args = this . triple ( Subject , Predicate , Object_or_Literal ) ;
477+ // if (Subject && Subject == 'args') return args
478+ this . cursor [ '@type' ] = 'AddTriple' ;
479+ return this . updated ( ) ;
480+ } ;
481+
482+ WOQLQuery . prototype . delete_quad = function ( a , b , c , g ) {
483+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
484+ const args = this . triple ( a , b , c ) ;
485+ // if (a && a == 'args') return args.concat(['graph'])
486+ if ( ! g ) {
487+ return this . parameterError (
488+ 'Delete Quad takes four parameters, the last should be a graph id' ,
489+ ) ;
490+ }
491+ this . cursor [ '@type' ] = 'DeleteTriple' ;
492+ this . cursor . graph = this . cleanGraph ( g ) ;
493+ return this . updated ( ) ;
494+ } ;
495+
496+ WOQLQuery . prototype . add_quad = function ( a , b , c , g ) {
497+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
498+ const args = this . triple ( a , b , c ) ;
499+ // if (a && a == 'args') return args.concat(['graph'])
500+ if ( ! g ) return this . parameterError ( 'Add Quad takes four parameters, the last should be a graph id' ) ;
501+ this . cursor [ '@type' ] = 'AddTriple' ;
502+ this . cursor . graph = this . cleanGraph ( g ) ;
503+ return this . updated ( ) ;
504+ } ;
505+
506+ WOQLQuery . prototype . trim = function ( untrimmed , trimmed ) {
507+ // if (untrimmed && untrimmed == 'args')
508+ // return ['untrimmed', 'trimmed']
509+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
510+ this . cursor [ '@type' ] = 'Trim' ;
511+ this . cursor . untrimmed = this . cleanDataValue ( untrimmed ) ;
512+ this . cursor . trimmed = this . cleanDataValue ( trimmed ) ;
513+ return this ;
514+ } ;
515+
516+ WOQLQuery . prototype . eval = function ( arith , res ) {
517+ // if (arith && arith == 'args')
518+ // return ['expression', 'result']
519+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
520+ this . cursor [ '@type' ] = 'Eval' ;
521+ this . cursor . expression = arith . json ? arith . json ( ) : arith ;
522+ this . cursor . result = this . cleanArithmeticValue ( res ) ;
523+ return this ;
524+ } ;
525+
526+ WOQLQuery . prototype . plus = function ( ...args ) {
527+ // if (args && args[0] == 'args') return ['first', 'second']
528+ if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
529+ this . cursor [ '@type' ] = 'Plus' ;
530+ this . cursor . left = this . arop ( args . shift ( ) ) ;
531+ if ( args . length > 1 ) {
532+ this . cursor . right = this . jobj ( new WOQLQuery ( ) . plus ( ...args ) ) ;
536533 } else {
537534 this . cursor . right = this . arop ( args [ 0 ] ) ;
538535 }
0 commit comments