@@ -391,146 +391,148 @@ 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- const iasv = this . asv ( i , varList [ 0 ] [ i ] ) ;
403- this . query . push ( iasv ) ;
404- }
405- } else {
406- // eslint-disable-next-line no-redeclare
407- for ( var i = 0 ; i < varList . length ; i ++ ) {
408- const onemap = varList [ i ] ;
409- if ( Array . isArray ( onemap ) && onemap . length >= 2 ) {
410- const type = onemap && onemap . length > 2 ? onemap [ 2 ] : false ;
411- const oasv = this . asv ( onemap [ 0 ] , onemap [ 1 ] , type ) ;
412- this . query . push ( oasv ) ;
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+ }
413414 }
414- }
415- }
416- } else if ( typeof varList [ 0 ] === 'number' || typeof varList [ 0 ] === 'string' ) {
417- if ( varList [ 2 ] && typeof varList [ 2 ] === 'string' ) {
418- var oasv = this . asv ( varList [ 0 ] , varList [ 1 ] , varList [ 2 ] ) ;
419- } else if ( varList [ 1 ] && typeof varList [ 1 ] === 'string' ) {
420- if ( varList [ 1 ] . substring ( 0 , 4 ) === 'xsd:' || varList [ 1 ] . substring ( 0 , 4 ) === 'xdd:' ) {
421- var oasv = this . asv ( this . query . length , varList [ 0 ] , varList [ 1 ] ) ;
422- } else {
423- var oasv = this . asv ( varList [ 0 ] , varList [ 1 ] ) ;
424- }
425- } else {
426- var oasv = this . asv ( this . query . length , varList [ 0 ] ) ;
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 ] )
427431 }
428- this . query . push ( oasv ) ;
429- } else if ( typeof varList [ 0 ] === 'object' ) {
430- // check if it is an class object with an json method
431- this . query . push ( varList [ 0 ] . json ? varList [ 0 ] . json ( ) : varList [ 0 ] ) ;
432- }
433- return this ;
434- } ;
435-
436- WOQLQuery . prototype . file = function ( fpath , opts ) {
437- // if (fpath && fpath === 'args') return ['file', 'format']
438- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
439- this . cursor [ '@type' ] = 'QueryResource' ;
440- this . cursor . source = { '@type' : 'Source' , file : fpath } ;
441- this . cursor . format = 'csv' ; // hard coded for now
442- if ( typeof opts !== 'undefined' ) 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' ) this . cursor . options = opts ;
453- return this ;
454- } ;
455-
456- WOQLQuery . prototype . post = function ( fpath , opts ) {
457- // if (fpath && fpath === 'args') return ['file', 'format']
458- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
459- this . cursor [ '@type' ] = 'PostResource' ;
460- this . cursor . source = { '@type' : 'Source' , file : fpath } ;
461- this . cursor . format = 'csv' ; // hard coded for now
462- this . cursor . options = opts ;
463- if ( typeof opts !== 'undefined' ) this . cursor . options = opts ;
464- return this ;
465- } ;
466-
467- WOQLQuery . prototype . delete_triple = function ( Subject , Predicate , Object_or_Literal ) {
468- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
469- const args = this . triple ( Subject , Predicate , Object_or_Literal ) ;
470- // if (Subject && Subject === 'args') return args
471- this . cursor [ '@type' ] = 'DeleteTriple' ;
472- return this . updated ( ) ;
473- } ;
474-
475- WOQLQuery . prototype . add_triple = function ( Subject , Predicate , Object_or_Literal ) {
476- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
477- const args = this . triple ( Subject , Predicate , Object_or_Literal ) ;
478- // if (Subject && Subject === 'args') return args
479- this . cursor [ '@type' ] = 'AddTriple' ;
480- return this . updated ( ) ;
481- } ;
482-
483- WOQLQuery . prototype . delete_quad = function ( a , b , c , g ) {
484- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
485- const args = this . triple ( a , b , c ) ;
486- // if (a && a === 'args') return args.concat(['graph'])
487- if ( ! g ) {
488- return this . parameterError (
489- 'Delete Quad takes four parameters, the last should be a graph id' ,
490- ) ;
491- }
492- this . cursor [ '@type' ] = 'DeleteTriple' ;
493- this . cursor . graph = this . cleanGraph ( g ) ;
494- return this . updated ( ) ;
495- } ;
496-
497- WOQLQuery . prototype . add_quad = function ( a , b , c , g ) {
498- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
499- const args = this . triple ( a , b , c ) ;
500- // if (a && a === 'args') return args.concat(['graph'])
501- if ( ! g ) return this . parameterError ( 'Add Quad takes four parameters, the last should be a graph id' ) ;
502- this . cursor [ '@type' ] = 'AddTriple' ;
503- this . cursor . graph = this . cleanGraph ( g ) ;
504- return this . updated ( ) ;
505- } ;
506-
507- WOQLQuery . prototype . trim = function ( untrimmed , trimmed ) {
508- // if (untrimmed && untrimmed === 'args')
509- // return ['untrimmed', 'trimmed']
510- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
511- this . cursor [ '@type' ] = 'Trim' ;
512- this . cursor . untrimmed = this . cleanDataValue ( untrimmed ) ;
513- this . cursor . trimmed = this . cleanDataValue ( trimmed ) ;
514- return this ;
515- } ;
516-
517- WOQLQuery . prototype . eval = function ( arith , res ) {
518- // if (arith && arith === 'args')
519- // return ['expression', 'result']
520- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
521- this . cursor [ '@type' ] = 'Eval' ;
522- this . cursor . expression = arith . json ? arith . json ( ) : arith ;
523- this . cursor . result = this . cleanArithmeticValue ( res ) ;
524- return this ;
525- } ;
526-
527- WOQLQuery . prototype . plus = function ( ...args ) {
528- // if (args && args[0] === 'args') return ['first', 'second']
529- if ( this . cursor [ '@type' ] ) this . wrapCursorWithAnd ( ) ;
530- this . cursor [ '@type' ] = 'Plus' ;
531- this . cursor . left = this . arop ( args . shift ( ) ) ;
532- if ( args . length > 1 ) {
533- this . cursor . right = this . jobj ( new WOQLQuery ( ) . plus ( ...args ) ) ;
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 ) )
534536 } else {
535537 this . cursor . right = this . arop ( args [ 0 ] ) ;
536538 }
0 commit comments