Skip to content

Commit e0b0f1f

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents f3ac03e + 940f85c commit e0b0f1f

File tree

6 files changed

+93
-70
lines changed

6 files changed

+93
-70
lines changed

dist/terminus-client.min.js

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/framePattern.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ const FramePatternMatcher = {};
1010
* A list of the matched rules is returned.
1111
*
1212
*/
13-
FramePatternMatcher.testRules = function (rules, frame, onmatch) {
14-
const matched_rules = [];
15-
for (let i = 0; i < rules.length; i++) {
16-
const match = (!rules[i].pattern || this.patternMatchesFrame(rules[i].pattern, frame));
17-
if (match) {
18-
matched_rules.push(rules[i]);
19-
if (onmatch && typeof onmatch === 'function') {
20-
onmatch(frame, rules[i]);
13+
FramePatternMatcher.testRules = function(rules, frame, onmatch){
14+
var matched_rules = [];
15+
if(rules && rules.length){
16+
for(var i = 0; i<rules.length; i++){
17+
var match = (!rules[i].pattern || FramePatternMatcher.patternMatchesFrame(rules[i].pattern, frame));
18+
if(match){
19+
matched_rules.push(rules[i]);
20+
if(onmatch && typeof onmatch == "function"){
21+
onmatch(frame, rules[i]);
22+
}
2123
}
2224
}
2325
}
@@ -64,8 +66,8 @@ FramePattern = function (pattern) {
6466
}
6567
};
6668

67-
FramePattern.prototype.setPattern = function (pattern) {
68-
this.renderer = (pattern.renderer ? pattern.renderer : false);
69+
FramePattern.prototype.setPattern = function(pattern){
70+
this.scope = (pattern.scope ? pattern.scope: false);
6971
this.label = (pattern.label ? pattern.label : false);
7072
this.frame_type = (pattern.frame_type ? pattern.frame_type : false);
7173
this.subject = (pattern.subject ? pattern.subject : false);
@@ -83,25 +85,25 @@ FramePattern.prototype.setPattern = function (pattern) {
8385
this.depth = (typeof pattern.depth !== 'undefined' ? pattern.depth : false);
8486
this.index = (pattern.index ? pattern.index : false);
8587
this.status = (pattern.status ? pattern.status : false);
86-
};
88+
}
8789

88-
FramePattern.prototype.checkFrame = function (frame) {
89-
const rtype = this.getRendererType(frame);
90-
if (!rtype) return false;
91-
if (this.renderer && (this.renderer != rtype) && (this.renderer != '*')) return false;
92-
if (this.illegalRuleType(rtype)) return false;
93-
if (this.frame_type && !this.checkFrameType(rtype, frame)) return false;
94-
if (this.label && !this.checkLabel(rtype, frame)) return false;
95-
if (this.subject && !this.checkSubject(rtype, frame)) return false;
96-
if (this.subjectClass && !this.checkSubjectClass(rtype, frame)) return false;
97-
if (this.property && !this.checkProperty(rtype, frame)) return false;
98-
if (this.depth !== false && !this.checkDepth(rtype, frame)) return false;
99-
if (this.range && !this.checkRange(rtype, frame)) return false;
100-
if (this.value && !this.checkValue(rtype, frame)) return false;
101-
if (this.parent && !this.checkParent(rtype, frame)) return false;
102-
if (this.children && this.children.length && !this.checkChildren(rtype, frame)) return false;
103-
if (this.index && !this.checkIndex(rtype, frame)) return false;
104-
if (this.status && !this.checkStatus(rtype, frame)) return false;
90+
FramePattern.prototype.checkFrame = function(frame){
91+
var rtype = this.getRendererType(frame);
92+
if(!rtype) return false;
93+
if(this.scope && (this.scope != rtype) && (this.scope != "*" )) return false;
94+
if(this.illegalRuleType(rtype)) return false;
95+
if(this.frame_type && !this.checkFrameType(rtype, frame)) return false;
96+
if(this.label && !this.checkLabel(rtype, frame)) return false;
97+
if(this.subject && !this.checkSubject(rtype, frame)) return false;
98+
if(this.subjectClass && !this.checkSubjectClass(rtype, frame)) return false;
99+
if(this.property && !this.checkProperty(rtype, frame)) return false;
100+
if(this.depth !== false && !this.checkDepth(rtype, frame)) return false;
101+
if(this.range && !this.checkRange(rtype, frame)) return false;
102+
if(this.value && !this.checkValue(rtype, frame)) return false;
103+
if(this.parent && !this.checkParent(rtype, frame)) return false;
104+
if(this.children && this.children.length && !this.checkChildren(rtype, frame)) return false;
105+
if(this.index && !this.checkIndex(rtype, frame)) return false;
106+
if(this.status && !this.checkStatus(rtype, frame)) return false;
105107
return true;
106108
};
107109

@@ -299,12 +301,12 @@ function FrameRule() {
299301
return this;
300302
}
301303

302-
FrameRule.prototype.renderer = function (...rend) {
303-
this.rule.pattern.renderer = rend;
304+
FrameRule.prototype.scope = function(scope){
305+
this.rule.pattern.scope = scope;
304306
return this;
305307
};
306308

307-
FrameRule.prototype.setRenderer = function (rend) {
309+
FrameRule.prototype.renderer = function(rend){
308310
this.rule.renderer = rend;
309311
return this;
310312
};
@@ -398,4 +400,4 @@ FrameRule.prototype.status = function (...status) {
398400
};
399401

400402

401-
module.exports = { FramePatternMatcher, FrameRule };
403+
module.exports = {FramePatternMatcher, FramePattern, FrameRule } ;

lib/objectFrame.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ ObjectFrame.prototype.empty = function () {
124124
// all indexed by property
125125
this.properties = {};
126126
this.restrictions = {};
127-
this.children = {};
128127
this.subjid = false;
129128
this.cls = false;
130129
};
@@ -696,6 +695,8 @@ DataFrame.prototype.copy = function (newid) {
696695

697696
DataFrame.prototype.getLabel = function () {
698697
let lab = '';
698+
if(this.predicate == "rdfs:label") return "Label";
699+
if(this.predicate == "rdfs:comment") return "Comment";
699700
if (this.label && typeof this.label === 'object') lab = this.label['@value'];
700701
if (this.label && typeof this.label === 'string') lab = this.label;
701702
// always return something
@@ -874,7 +875,6 @@ DataFrame.prototype.clear = function () {
874875
function ClassFrame(frame, parent) {
875876
this.err = false;
876877
this.parent = parent;
877-
this.children = {};
878878
// the id of the object that owns this dataframe
879879
this.subjid = (parent ? parent.subjid : false);
880880
if (frame) {

lib/woql.js

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* Syntactic sugar to allow you to write WOQL.triple()... instead of new WOQLQuery().triple()
44
* Every function matches one of the public api functions of the woql query object
55
*/
6-
const FramePattern = require('./framePattern');
76
const FrameHelper = require('./frameHelper');
7+
const Pattern = require('./framePattern');
88

99
const WOQL = {};
1010

11+
/*
12+
* We expose all the real woql predicates via the WOQL object,
13+
* for ease of typing - all return a WOQL query object
14+
*/
1115
WOQL.when = function(Query, Update){ return new WOQLQuery().when(Query, Update);}
1216
WOQL.opt = function(query){ return new WOQLQuery().opt(query); }
1317
WOQL.from = function(dburl, query){ return new WOQLQuery().from(dburl, query); }
@@ -34,21 +38,26 @@ WOQL.times = function(...args){ return new WOQLQuery().times(...args); }
3438
WOQL.divide = function(...args){ return new WOQLQuery().divide(...args); }
3539
WOQL.exp = function(a, b){ return new WOQLQuery().exp(a, b); }
3640

37-
WOQL.schema = function(){ return new WOQLSchema(); }
38-
39-
WOQL.query = function(){ return new WOQLQuery(); }
40-
4141
WOQL.get = function(map, target){ return new WOQLQuery().get(map, target); }
4242
WOQL.as = function(map, vari){ return new WOQLQuery().as(map, vari); }
4343
WOQL.remote = function(url){ return new WOQLQuery().remote(url); }
4444
WOQL.unique = function(prefix, vari){ return new WOQLQuery().unique(prefix, vari); }
4545
WOQL.list = function(vars){ return new WOQLQuery().list(vars); }
4646
//WOQL.value = function(vars){ return new WOQLQuery().list(vars); }
4747

48-
48+
/*
49+
* Beneath here are pseudo predicates - they belong to the javascript object
50+
* but not to the WOQL language
51+
*/
52+
//returns empty query object
53+
WOQL.query = function(){ return new WOQLQuery(); }
54+
//loads query from json
4955
WOQL.json = function(json){ return new WOQLQuery().json(json); }
50-
WOQL.rule = function(){ return new FramePattern.FrameRule() }
56+
//returns a special schema object for terse schema updates
57+
WOQL.schema = function(){ return new WOQLSchema(); }
5158

59+
WOQL.rule = function(){ return new Pattern.FrameRule(); }
60+
//Simple utility function for typechecking
5261
WOQL.isLiteralType = function(t){
5362
if(t){
5463
var pref = t.split(":");
@@ -57,11 +66,14 @@ WOQL.isLiteralType = function(t){
5766
return false;
5867
};
5968

60-
61-
function WOQLQuery(query, results) {
62-
this.query = (query || {});
69+
/**
70+
* The WOQL Query object implements the WOQL language via the fluent style
71+
* @param query - json version of query
72+
* @returns WOQLQuery object
73+
*/
74+
function WOQLQuery(query){
75+
this.query = (query ? query : {});
6376
this.cursor = this.query;
64-
this.results = (results || false);
6577
this.chain_ended = false;
6678
this.contains_update = false;
6779
// operators which preserve global paging
@@ -274,10 +286,9 @@ WOQLQuery.prototype.getSelectVariables = function (q) {
274286
}
275287
};
276288

277-
278-
WOQLQuery.prototype.setStart = function (start) {
279-
return this.setPagingProperty('start', start);
280-
};
289+
WOQLQuery.prototype.setStart = function(start){
290+
return this.setPagingProperty("start", start);
291+
}
281292

282293
WOQLQuery.prototype.setPageSize = function (size) {
283294
this.setPagingProperty('limit', size);
@@ -367,10 +378,9 @@ WOQLQuery.prototype.opt = function (query) {
367378
return this;
368379
};
369380

370-
371-
WOQLQuery.prototype.from = function (dburl, query) {
372-
this.advanceCursor('from', dburl);
373-
if (query) {
381+
WOQLQuery.prototype.from = function(dburl, query){
382+
this.advanceCursor("from", dburl);
383+
if(query){
374384
this.cursor = query.json();
375385
}
376386
return this;
@@ -745,7 +755,29 @@ WOQLSchema.prototype.cardinality = function (m) {
745755

746756
WOQLSchema.prototype.domain = function (d) {
747757
return this.addPO('rdfs:domain', d);
748-
};
758+
}
759+
/*
760+
*
761+
762+
let s = WOQL.schema();
763+
s.addClass("myclass").label("whatever").comment("yo").entity();
764+
s.addProperty("myprop", "string").label("whatever").comment("yo").domain("myclass").max(1);
765+
s.execute(client).then()
766+
767+
WOQL.when(WQOL.query().get(mytwitterfriends).column("adfa").as("v:X").update(triple(v:X));
768+
769+
WOQL.select("fadfadf").execute().done()
770+
g = WOQL.graph()....
771+
show(result, g);
772+
773+
*
774+
*
775+
*
776+
*
777+
778+
779+
*
780+
*/
749781

750782

751783
module.exports = WOQL;

lib/woqlResult.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ WOQLResult.prototype.prev = function () {
4848
}
4949
};
5050

51-
WOQLResult.prototype.compareValues = function (a, b, asc_or_desc) {
52-
if (a['@value'] && b['@value']) {
51+
WOQLResult.prototype.compareValues = function(a, b, asc_or_desc){
52+
if(!a || !b) return 0;
53+
if(typeof a['@value'] != "undefined" && typeof b['@value'] != "undefined"){
5354
a = a['@value'];
5455
b = b['@value'];
5556
}

0 commit comments

Comments
 (0)