Skip to content

Commit ff0b9d0

Browse files
updated new client code to make it work with packaging system
1 parent 2b0b300 commit ff0b9d0

File tree

10 files changed

+132
-103
lines changed

10 files changed

+132
-103
lines changed

dist/terminus-client.min.js

Lines changed: 4 additions & 4 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 & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
'use strict';
2-
module.exports = {WOQLClient:require('./lib/woqlClient'),
2+
module.exports = {
3+
WOQLClient:require('./lib/woqlClient'),
34
ConnectionCapabilities:require('./lib/connectionCapabilities'),
45
ConnectionConfig:require('./lib/connectionConfig'),
56
IDParser:require('./lib/terminusIDParser'),
67
ErrorMessage:require('./lib/errorMessage'),
78
FrameHelper:require('./lib/frameHelper'),
8-
ObjectFrame:require('./lib/objectFrame')};
9+
ObjectFrame:require('./lib/objectFrame'),
10+
TerminusDocumentViewer:require('./lib/documentViewer'),
11+
WOQLViewer:require('./lib/woqlViewer'),
12+
WOQL:require('./lib/woql')};

lib/viewers.js renamed to lib/documentViewer.js

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -168,45 +168,4 @@ FilteredDocumentViewer.prototype.render = function(doc){
168168
}
169169
}
170170

171-
function WOQLViewer(client, config){
172-
this.client = client;
173-
this.config = config;
174-
return this;
175-
}
176-
177-
WOQLViewer.prototype.query = function(query){
178-
this.query = query;
179-
return this;
180-
}
181-
182-
WOQLViewer.prototype.show = function(then){
183-
return this.query.execute(this.client).then((results) => {
184-
this.result = new WOQLResult(results, this.query);
185-
this.render(this.result, then);
186-
});
187-
return this;
188-
}
189-
190-
WOQLViewer.prototype.render = function(wres, then){
191-
let renderer = this.getRenderer(wres);
192-
if(wres && renderer){
193-
if(renderer.render){
194-
var rendered = renderer.render(wres, this.query);
195-
}
196-
else {
197-
var rendered = renderer(wres, this.query);
198-
}
199-
if(then){
200-
then(rendered, wres, then);
201-
}
202-
}
203-
return rendered || false;
204-
}
205-
206-
WOQLViewer.prototype.setRenderer = function(renderer){
207-
this.renderer = renderer;
208-
}
209-
210-
WOQLViewer.prototype.getRenderer = function(results){
211-
if(this.renderer) return this.renderer;
212-
}
171+
module.exports = TerminusDocumentViewer ;

lib/framePattern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,4 @@ FrameRule.prototype.status = function(...status){
403403
}
404404

405405

406-
//module.exports = FramePatternMatcher ;
406+
module.exports = {FramePatternMatcher, FrameRule} ;

lib/objectFrame.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @returns
1313
*/
1414
const FrameHelper = require('./frameHelper');
15-
//const FramePatternMatcher = require('./framePattern');
15+
const FramePattern = require('./framePattern');
1616

1717
function ObjectFrame(cls, dataframes, classframes, parent, parentframe) {
1818
// the class of the frame - mandatory
@@ -164,7 +164,7 @@ ObjectFrame.prototype.clear = function () {
164164
*/
165165
ObjectFrame.prototype.filter = function (rules, onmatch, options) {
166166
const cascading = (options && options.ignore_failure ? true : false);
167-
var hits = FramePatternMatcher.testRules(rules, this, onmatch);
167+
var hits = FramePattern.FramePatternMatcher.testRules(rules, this, onmatch);
168168
if(hits.length || cascading){
169169
for (const prop of Object.keys(this.properties)) {
170170
this.properties[prop].filter(rules, onmatch, options);
@@ -563,7 +563,7 @@ PropertyFrame.prototype.createEmpty = function(){
563563

564564
PropertyFrame.prototype.filter = function (rules, onmatch, options) {
565565
const cascading = (options && options.ignore_failure ? true : false);
566-
var hits = FramePatternMatcher.testRules(rules, this, onmatch);
566+
var hits = FramePattern.FramePatternMatcher.testRules(rules, this, onmatch);
567567
if(hits.length || cascading){
568568
for (var i = 0; i<this.values.length; i++){
569569
this.values[i].filter(rules, onmatch, options);
@@ -636,11 +636,10 @@ DataFrame.prototype.load = function (frame) {
636636
};
637637

638638
DataFrame.prototype.filter = function (rules, onmatch) {
639-
FramePatternMatcher.testRules(rules, this, onmatch);
639+
FramePattern.FramePatternMatcher.testRules(rules, this, onmatch);
640640
return this;
641641
}
642642

643-
644643
DataFrame.prototype.delete = function(){
645644
this.parent.deletePropertyValue(this.get(), this.index);
646645
}
@@ -672,9 +671,6 @@ DataFrame.prototype.subject = function(){ return (this.parent ? this.parent.subj
672671
DataFrame.prototype.subjectClass = function(){ return (this.parent ? this.parent.subjectClass() : false);};
673672
DataFrame.prototype.range = function(){ return (this.frame ? this.frame.range : false);};
674673

675-
676-
677-
678674
DataFrame.prototype.isValidType = function (dt) {
679675
const vtypes = ['datatypeProperty', 'objectProperty', 'restriction '];
680676
if (vtypes.indexOf(dt) === -1) return false;

lib/woql.js

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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');
7+
68
const WOQL = {};
79
WOQL.when = function(Query, Update){ return new WOQLQuery().when(Query, Update);}
810
WOQL.opt = function(query){ return new WOQLQuery().opt(query); }
@@ -29,7 +31,7 @@ WOQL.minus = function(...args){ return new WOQLQuery().minus(...args); }
2931
WOQL.times = function(...args){ return new WOQLQuery().times(...args); }
3032
WOQL.divide = function(...args){ return new WOQLQuery().divide(...args); }
3133
WOQL.exp = function(a, b){ return new WOQLQuery().exp(a, b); }
32-
WOQL.rule = function(){ return new FrameRule() }
34+
WOQL.rule = function(){ return new FramePattern.FrameRule() }
3335

3436
function WOQLQuery(query, results){
3537
this.query = (query ? query : {});
@@ -130,7 +132,6 @@ WOQLQuery.prototype.setLimit = function(limit){
130132
return this.setPagingProperty("limit", limit);
131133
}
132134

133-
134135
WOQLQuery.prototype.getLimit = function(){
135136
return this.getPagingProperty("limit");
136137
}
@@ -213,14 +214,13 @@ WOQLQuery.prototype.context = function(Context){
213214
}
214215

215216
WOQLQuery.prototype.defaultContext = function(DB_IRI){
216-
let def = {
217-
"db": DB_IRI + "/",
218-
"scm": DB_IRI + "/schema#",
219-
"doc": DB_IRI + "/document/"
220-
}
217+
let def = {}
221218
for(var pref in TerminusClient.FrameHelper.standard_urls){
222219
def[pref] = TerminusClient.FrameHelper.standard_urls[pref];
223220
}
221+
def.db = DB_IRI + "/";
222+
def.scm = def.db + "/schema#"
223+
def.doc = def.db + "/document/"
224224
return def;
225225
}
226226

@@ -531,38 +531,4 @@ WOQLQuery.prototype.getInstanceMeta = function(url){
531531
);
532532
}
533533

534-
function WOQLResult(results, query){
535-
this.bindings = results.bindings;
536-
this.query = query;
537-
this.compress();
538-
}
539-
540-
WOQLResult.prototype.compress = function(context){
541-
context = (context ? context : this.query.getContext());
542-
for(var i = 0; i<this.bindings.length; i++){
543-
for (const prop of Object.keys(this.bindings[i])) {
544-
const nprop = TerminusClient.FrameHelper.shorten(prop, context);
545-
const nval = ((typeof this.bindings[i][prop] == "string")
546-
? TerminusClient.FrameHelper.shorten(this.bindings[i][prop], context)
547-
: this.bindings[i][prop]
548-
);
549-
delete(this.bindings[i][prop]);
550-
this.bindings[i][nprop] = nval;
551-
}
552-
}
553-
}
554-
555-
556-
WOQLResult.prototype.count = function(){
557-
return this.bindings.length;
558-
}
559-
560-
WOQLResult.prototype.hasBindings = function(result){
561-
return (this.bindings && this.bindings.count());
562-
}
563-
564-
WOQLResult.prototype.getBindings = function(){
565-
return this.bindings;
566-
}
567-
568-
534+
module.exports = WOQL ;

lib/woqlResult.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function WOQLResult(results, query, config){
2+
this.bindings = results.bindings;
3+
this.query = query;
4+
this.cursor = 0;
5+
if(!(config && config.no_compress)){
6+
var context = (config && config.context ? config.context : false);
7+
this.compress(context);
8+
}
9+
}
10+
11+
WOQLResult.prototype.compress = function(context){
12+
context = (context ? context : this.query.getContext());
13+
for(var i = 0; i<this.bindings.length; i++){
14+
for (const prop of Object.keys(this.bindings[i])) {
15+
const nprop = TerminusClient.FrameHelper.shorten(prop, context);
16+
const nval = ((typeof this.bindings[i][prop] == "string")
17+
? TerminusClient.FrameHelper.shorten(this.bindings[i][prop], context)
18+
: this.bindings[i][prop]
19+
);
20+
delete(this.bindings[i][prop]);
21+
this.bindings[i][nprop] = nval;
22+
}
23+
}
24+
}
25+
26+
WOQLResult.prototype.first = function(){
27+
return this.bindings[0];
28+
}
29+
30+
WOQLResult.prototype.last = function(){
31+
return this.bindings[this.bindings.length-1];
32+
}
33+
34+
WOQLResult.prototype.next = function(){
35+
this.cursor++;
36+
return this.bindings[this.cursor];
37+
}
38+
39+
WOQLResult.prototype.prev = function(){
40+
if(this.cursor > 0){
41+
this.cursor--;
42+
return this.bindings[this.cursor];
43+
}
44+
}
45+
46+
WOQLResult.prototype.count = function(){
47+
return this.bindings.length;
48+
}
49+
50+
WOQLResult.prototype.hasBindings = function(result){
51+
return (this.bindings && this.bindings.count());
52+
}
53+
54+
WOQLResult.prototype.getBindings = function(){
55+
return this.bindings;
56+
}
57+
58+
module.exports = WOQLResult;

lib/woqlViewer.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const WOQLResult = require('./woqlResult');
2+
3+
4+
function WOQLViewer(client, config){
5+
this.client = client;
6+
this.config = config;
7+
return this;
8+
}
9+
10+
WOQLViewer.prototype.query = function(query){
11+
this.query = query;
12+
return this;
13+
}
14+
15+
WOQLViewer.prototype.show = function(then){
16+
return this.query.execute(this.client).then((results) => {
17+
this.result = new WOQLResult(results, this.query);
18+
this.render(this.result, then);
19+
});
20+
return this;
21+
}
22+
23+
WOQLViewer.prototype.render = function(wres, then){
24+
let renderer = this.getRenderer(wres);
25+
if(wres && renderer){
26+
if(renderer.render){
27+
var rendered = renderer.render(wres, this.query);
28+
}
29+
else {
30+
var rendered = renderer(wres, this.query);
31+
}
32+
if(then){
33+
then(rendered, wres, then);
34+
}
35+
}
36+
return rendered || false;
37+
}
38+
39+
WOQLViewer.prototype.setRenderer = function(renderer){
40+
this.renderer = renderer;
41+
}
42+
43+
WOQLViewer.prototype.getRenderer = function(results){
44+
if(this.renderer) return this.renderer;
45+
}
46+
47+
module.exports = WOQLViewer;

test.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
<title>Woql Client</title>
66
</head>
77
<body>
8-
<script type="text/javascript" src="lib/woql.js"></script>
9-
<script type="text/javascript" src="lib/viewers.js"></script>
10-
<script type="text/javascript" src="lib/framePattern.js"></script>
118
<script type="text/javascript" src="lib/htmlViewers.js"></script>
129
<script src="http://localhost/terminus-client/dist/terminus-client.min.js"></script>
1310
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
@@ -16,6 +13,8 @@
1613

1714
<script type="text/javascript">
1815

16+
var WOQL = TerminusClient.WOQL;
17+
1918
function showTerminus(doc){
2019
document.getElementById('dvterm').appendChild(document.createTextNode(doc.subjid));
2120
const lab = doc.first("rdfs:label") || doc.subjid;

0 commit comments

Comments
 (0)