Skip to content

Commit 47daf38

Browse files
committed
2 parents bdac44f + 7d90824 commit 47daf38

File tree

11 files changed

+211
-38
lines changed

11 files changed

+211
-38
lines changed

docs/api/woql.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Every function matches one of the public api functions of the woql query object
1010

1111

1212
## using
13-
##### WOQL.using(refPath, subquery) ⇒ <code>WOQLQuery</code>
13+
##### WOQL.using(refPath, [subquery]) ⇒ <code>WOQLQuery</code>
1414
Query running against any specific commit Id
1515

1616

1717
| Param | Type | Description |
1818
| --- | --- | --- |
1919
| refPath | <code>string</code> | path to specific reference Id or commit Id |
20-
| subquery | <code>WOQLQuery</code> | subquery for the specific commit point |
20+
| [subquery] | <code>WOQLQuery</code> | subquery for the specific commit point |
2121

2222
**Example**
2323
```javascript
@@ -26,14 +26,14 @@ WOQL.using("userName/dbName/local/commit|branch/commitID").triple(a, b, c)
2626
```
2727

2828
## comment
29-
##### WOQL.comment(comment, subquery) ⇒ <code>WOQLQuery</code>
29+
##### WOQL.comment(comment, [subquery]) ⇒ <code>WOQLQuery</code>
3030
Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
3131

3232

3333
| Param | Type | Description |
3434
| --- | --- | --- |
3535
| comment | <code>string</code> | text comment |
36-
| subquery | <code>WOQLQuery</code> | query that is "commented out" |
36+
| [subquery] | <code>WOQLQuery</code> | query that is "commented out" |
3737

3838

3939
## select
@@ -182,15 +182,15 @@ Specifies the database URL that will be the default database for the enclosed qu
182182

183183

184184
## into
185-
##### WOQL.into(graphRef-, subquery) ⇒ <code>WOQLQuery</code>
185+
##### WOQL.into(graphRef-, [subquery]) ⇒ <code>WOQLQuery</code>
186186
Specifies the graph resource to write the contained query into
187187

188188
**Returns**: <code>WOQLQuery</code> - A WOQLQuery which will be written into the graph in question
189189

190190
| Param | Type | Description |
191191
| --- | --- | --- |
192192
| graphRef- | <code>typedef.GraphRef</code> | A valid graph resource identifier string |
193-
| subquery | <code>WOQLQuery</code> | The query which will be written into the graph |
193+
| [subquery] | <code>WOQLQuery</code> | The query which will be written into the graph |
194194

195195
**Example**
196196
```javascript

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const WOQLTable = require('./lib/viewer/woqlTable');
99
const WOQLGraph = require('./lib/viewer/woqlGraph');
1010
const axiosInstance = require('./lib/axiosInstance');
1111
const AccessControl = require('./lib/accessControl');
12+
const WOQLQuery = require('./lib/query/woqlBuilder');
1213

1314
module.exports = {
1415
Vars,
@@ -21,4 +22,5 @@ module.exports = {
2122
WOQLGraph,
2223
axiosInstance,
2324
AccessControl,
25+
WOQLQuery,
2426
};

lib/query/woqlBuilder.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,28 @@
1010
*
1111
*/
1212

13-
const WOQLQuery = require('./woqlQuery');
14-
const WOQLLibrary = require('./woqlLibrary');
13+
/**
14+
* defines the internal functions of the woql query object - the
15+
* language API is defined in WOQLQuery
16+
* @module WOQLQuery
17+
* @constructor
18+
* @param {object} [query] json-ld query for initialisation
19+
* @returns {WOQLQuery}
20+
*/
1521

16-
WOQLQuery.prototype.counter = 1;
17-
/* class WOQLQuery extends WOQLQueryImp {
18-
constructor(query) {
19-
super(query)
20-
}
21-
} */
22+
const WOQLQueryExt = require('./woqlQuery');
23+
// const WOQLLibrary = require('./woqlLibrary');
24+
25+
class WOQLQuery extends WOQLQueryExt {
26+
counter = 1;
27+
28+
// eslint-disable-next-line no-useless-constructor
29+
constructor(query) {
30+
super(query);
31+
}
32+
}
33+
34+
// WOQLQuery.prototype.counter = 1;
2235

2336
/**
2437
* Simple composite functions which produce WOQL queries
@@ -38,9 +51,9 @@ WOQLQuery.prototype.all = function (Subj, Pred, Obj, Graph) {
3851
return this.star(Graph, Subj, Pred, Obj);
3952
};
4053

41-
WOQLQuery.prototype.lib = function () {
54+
/* WOQLQuery.prototype.lib = function () {
4255
return new WOQLLibrary();
43-
};
56+
}; */
4457

4558
WOQLQuery.prototype.string = function (s) {
4659
return { '@type': 'xsd:string', '@value': String(s) };

lib/query/woqlCore.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const { Var, Vars, Doc } = require('./woqlDoc');
2424
* @param {object} [query] json-ld query for initialisation
2525
* @returns {WOQLQuery}
2626
*/
27-
function WOQLQuery(query) {
27+
/* function WOQLQuery(query) {
2828
this.query = query || {};
2929
this.errors = [];
3030
this.cursor = this.query;
@@ -47,6 +47,53 @@ function WOQLQuery(query) {
4747
// object used to accumulate triples from fragments to support usage like node("x").label("y");
4848
this.tripleBuilder = false;
4949
return this;
50+
} */
51+
52+
class WOQLQuery {
53+
query = null;
54+
55+
errors = [];
56+
57+
cursor = {};
58+
59+
chain_ended = false;
60+
61+
contains_update = false;
62+
63+
// operators which preserve global paging
64+
paging_transitive_properties = ['select', 'from', 'start', 'when', 'opt', 'limit'];
65+
66+
update_operators = [
67+
'AddTriple',
68+
'DeleteTriple',
69+
'AddQuad',
70+
'DeleteQuad',
71+
'InsertDocument',
72+
'DeleteDocument',
73+
'UpdateDocument',
74+
];
75+
76+
vocab = this.loadDefaultVocabulary();
77+
78+
// object used to accumulate triples from fragments to support usage like node("x").label("y");
79+
tripleBuilder = false;
80+
/**
81+
* defines the internal functions of the woql query object - the
82+
* language API is defined in WOQLQuery
83+
* @module WOQLQuery
84+
* @constructor
85+
* @param {object} [query] json-ld query for initialisation
86+
* @returns {WOQLQuery}
87+
*/
88+
89+
constructor(query) {
90+
this.query = query || {};
91+
// this.errors = [];
92+
this.cursor = this.query;
93+
94+
// eslint-disable-next-line no-constructor-return
95+
return this;
96+
}
5097
}
5198

5299
/**

lib/query/woqlLibrary.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// /@ts-check
2-
const WOQLQuery = require('./woqlCore');
2+
// we can not import woqlBuilder because woqlBuilder import WOQLLibrary
3+
const WOQLQuery = require('./woqlBuilder');
34

45
/**
56
* @license Apache Version 2
@@ -13,12 +14,16 @@ const WOQLQuery = require('./woqlCore');
1314
* //or you can call this functions using WOQL Class
1415
* WOQL.lib().branches()
1516
* */
16-
function WOQLLibrary() {
17-
this.default_schema_resource = 'schema/main';
18-
this.default_commit_resource = '_commits';
19-
this.default_meta_resource = '_meta';
20-
this.masterdb_resource = '_system';
21-
this.empty = '';
17+
class WOQLLibrary {
18+
default_schema_resource = 'schema/main';
19+
20+
default_commit_resource = '_commits';
21+
22+
default_meta_resource = '_meta';
23+
24+
masterdb_resource = '_system';
25+
26+
empty = '';
2227
}
2328

2429
/**

lib/query/woqlQuery.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable class-methods-use-this */
12
/* eslint-disable no-redeclare */
23
/* eslint-disable block-scoped-var */
34
/* eslint-disable no-var */
@@ -11,15 +12,48 @@
1112
/* eslint-disable no-restricted-syntax */
1213
/// /@ts-check
1314
// WOQLQuery
14-
const WOQLQuery = require('./woqlCore');
15+
/**
16+
* defines the internal functions of the woql query object - the
17+
* language API is defined in WOQLQuery
18+
* @module WOQLQuery
19+
* @constructor
20+
* @param {object} [query] json-ld query for initialisation
21+
* @returns {WOQLQuery}
22+
*/
23+
24+
const WOQLCore = require('./woqlCore');
1525
const { Var, Vars, Doc } = require('./woqlDoc');
1626

1727
// I HAVE TO REVIEW THE Inheritance and the prototype chain
18-
/* class WOQLQuery extends WOQLCore {
19-
constructor(query) {
20-
super(query)
21-
}
22-
} */
28+
class WOQLQuery extends WOQLCore {
29+
/**
30+
* defines the internal functions of the woql query object - the
31+
* language API is defined in WOQLQuery
32+
* @module WOQLQuery
33+
* @constructor
34+
* @param {object} [query] json-ld query for initialisation
35+
* @returns {WOQLQuery}
36+
*/
37+
38+
update_triple(subject, predicate, new_object, old_object) {}
39+
40+
star(Graph, Subj, Pred, Obj) {}
41+
42+
update_quad(subject, predicate, new_object, graph) {}
43+
44+
insert(id, type, refGraph) {}
45+
46+
graph(g) {}
47+
48+
node(node, type) {}
49+
50+
nuke(g) {}
51+
52+
// eslint-disable-next-line no-useless-constructor
53+
constructor(query) {
54+
super(query);
55+
}
56+
}
2357

2458
WOQLQuery.prototype.read_document = function (IRI, OutputVar) {
2559
if (this.cursor['@type']) this.wrapCursorWithAnd();

lib/viewer/tableConfig.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ WOQLTableConfig.prototype.json = function () {
3131
if (typeof this.renderer() !== 'undefined') {
3232
conf.renderer = this.renderer();
3333
}
34+
if (typeof this.filter() !== 'undefined') {
35+
conf.filter = this.filter();
36+
}
37+
if (typeof this.filterable() !== 'undefined') {
38+
conf.filterable = this.filterable();
39+
}
3440
if (typeof this.pager() !== 'undefined') {
3541
conf.pager = this.pager();
3642
}
@@ -68,6 +74,12 @@ WOQLTableConfig.prototype.loadJSON = function (config, rules) {
6874
if (typeof config.renderer !== 'undefined') {
6975
this.renderer(config.renderer);
7076
}
77+
if (typeof config.filter !== 'undefined') {
78+
this.filter(config.filter);
79+
}
80+
if (typeof config.filterable !== 'undefined') {
81+
this.filterable(config.filterable);
82+
}
7183
if (typeof config.bindings !== 'undefined') {
7284
this.bindings(config.bindings);
7385
}
@@ -111,6 +123,27 @@ WOQLTableConfig.prototype.prettyPrint = function () {
111123
return str;
112124
};
113125

126+
/**
127+
* @param {boolean} canfilter
128+
* @returns WOQLTableConfig
129+
*/
130+
131+
WOQLTableConfig.prototype.filterable = function (canfilter) {
132+
if (!canfilter && canfilter !== false) return this.tfilterable;
133+
this.tfilterable = canfilter;
134+
return this;
135+
};
136+
137+
/*
138+
* default is string
139+
* filter type number | list | date
140+
*/
141+
WOQLTableConfig.prototype.filter = function (filter) {
142+
if (!filter) return this.tfilter;
143+
this.tfilter = filter;
144+
return this;
145+
};
146+
114147
WOQLTableConfig.prototype.renderer = function (rend) {
115148
if (!rend) return this.trenderer;
116149
this.trenderer = rend;
@@ -196,6 +229,22 @@ WOQLTableRule.prototype.header = function (hdr) {
196229
return this;
197230
};
198231

232+
WOQLTableRule.prototype.filter = function (hdr) {
233+
if (typeof hdr === 'undefined') {
234+
return this.rule.filter;
235+
}
236+
this.rule.filter = hdr;
237+
return this;
238+
};
239+
240+
WOQLTableRule.prototype.filterable = function (hdr) {
241+
if (typeof hdr === 'undefined') {
242+
return this.rule.filterable;
243+
}
244+
this.rule.filterable = hdr;
245+
return this;
246+
};
247+
199248
WOQLTableRule.prototype.width = function (wid) {
200249
if (typeof wid === 'undefined') {
201250
return this.rule.width;

lib/viewer/terminusRule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ TerminusPattern.prototype.testBasics = function (scope, value) {
112112
};
113113

114114
TerminusPattern.prototype.testValue = function (value, constraint) {
115+
if (!value) return null;
115116
const vundertest = (value['@value'] ? value['@value'] : value);
116117
if (typeof constraint === 'function') return constraint(vundertest);
117118
// eslint-disable-next-line no-param-reassign

0 commit comments

Comments
 (0)