Skip to content

Commit f794a96

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 9b55727 + 5a6d4f9 commit f794a96

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

lib/woql.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ WOQL.unique = function(prefix, vari, type){ return new WOQLQuery().unique(prefix
5151
WOQL.idgen = function(prefix, vari, type, output){ return new WOQLQuery().idgen(prefix, vari, type, output); }
5252
WOQL.typecast = function(vara, type, varb){ return new WOQLQuery().typecast(vara, type, varb); }
5353

54+
WOQL.less = function(v1, v2){ return new WOQLQuery().less(v1, v2); }
55+
WOQL.greater = function(v1, v2){ return new WOQLQuery().greater(v1, v2); }
56+
5457

5558
/* Mathematical Processing */
5659
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
@@ -286,6 +289,16 @@ WOQLQuery.prototype.join = function(...list){
286289
return this;
287290
}
288291

292+
WOQLQuery.prototype.less = function(v1, v2){
293+
this.cursor['less'] = [v1, v2];
294+
return this;
295+
}
296+
297+
WOQLQuery.prototype.greater = function(v1, v2){
298+
this.cursor['greater'] = [v1, v2];
299+
return this;
300+
}
301+
289302

290303
WOQLQuery.prototype.list = function(...vars){
291304
this.cursor['list'] = vars;
@@ -440,14 +453,22 @@ WOQLQuery.prototype.sub = function(a, b){
440453
}
441454

442455
WOQLQuery.prototype.comment = function(val){
443-
if(val){
444-
val = (val.json ? val.json() : val)
445-
this.cursor['comment'] = val;
456+
if(val && val.json){
457+
this.cursor['comment'] = [val.json()];
458+
}
459+
else if(typeof val == "string"){
460+
this.cursor['comment'] = [{"@value": val, "@language": "en"}];
461+
}
462+
else if(typeof val == "object"){
463+
if(val.length) this.cursor['comment'] = val;
464+
else this.cursor['comment'] = [val];
446465
}
447466
else {
448-
this.cursor['comment'] = null;
449-
this.cursor = this.cursor['comment'];
467+
this.cursor['comment'] = [];
450468
}
469+
var last_index = this.cursor['comment'].length;
470+
this.cursor['comment'][last_index] = {};
471+
this.cursor = this.cursor['comment'][last_index];
451472
return this;
452473
}
453474

@@ -684,7 +705,7 @@ WOQLQuery.prototype.label = function(l, lang){
684705
}
685706

686707
WOQLQuery.prototype.description = function(c, lang){
687-
if(this.tripleBuilder) this.tripleBuilder.comment(c, lang);
708+
if(this.tripleBuilder) this.tripleBuilder.description(c, lang);
688709
return this;
689710
}
690711

@@ -1219,7 +1240,7 @@ WOQLQuery.prototype.getWOQLPrelude = function(operator, fluent, inline){
12191240
*/
12201241
WOQLQuery.prototype.chainable = function(operator, lastArg){
12211242
const non_chaining_operators = ["and", "or"];
1222-
if(typeof lastArg == "object" && typeof lastArg['@value'] == "undefined" && typeof lastArg['@type'] == "undefined" && typeof lastArg['value'] == "undefined" && non_chaining_operators.indexOf(operator) == -1){
1243+
if(lastArg && typeof lastArg == "object" && typeof lastArg['@value'] == "undefined" && typeof lastArg['@type'] == "undefined" && typeof lastArg['value'] == "undefined" && non_chaining_operators.indexOf(operator) == -1){
12231244
return true;
12241245
}
12251246
return false;
@@ -1348,9 +1369,13 @@ WOQLQuery.prototype.uncleanObjectArgument = function(operator, val, index){
13481369
return JSON.stringify(val);
13491370
}
13501371

1351-
WOQLQuery.prototype.argIsSubQuery = function(operator, args){
1352-
const squery_operators = ["and", "or", "when", "not", "opt"];
1353-
return (squery_operators.indexOf(operator) !== -1);
1372+
WOQLQuery.prototype.argIsSubQuery = function(operator, arg, index){
1373+
const squery_operators = ["and", "or", "when", "not", "opt", "exp", "minus", "div", "divide", "plus", "multiply"];
1374+
if(squery_operators.indexOf(operator) !== -1){
1375+
if(arg && typeof arg != "object") return false;
1376+
return true;
1377+
}
1378+
else return false;
13541379
}
13551380

13561381
/**
@@ -1463,7 +1488,7 @@ TripleBuilder.prototype.label = function(l, lang){
14631488
return x;
14641489
}
14651490

1466-
TripleBuilder.prototype.comment = function(c, lang){
1491+
TripleBuilder.prototype.description = function(c, lang){
14671492
lang = (lang ? lang : "en");
14681493
if(c.substring(0, 2) == "v:"){
14691494
var d = {"value": l, "@language": lang }

0 commit comments

Comments
 (0)