Skip to content

Commit c1d9550

Browse files
committed
review woql for typescript
1 parent a791720 commit c1d9550

File tree

7 files changed

+132
-28
lines changed

7 files changed

+132
-28
lines changed

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/woql.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// /@ts-check
44
// I HAVE TO REVIEW THE Inheritance and the prototype chain
55
const WOQLQuery = require('./query/woqlBuilder');
6+
const WOQLLibrary = require('./query/woqlLibrary');
67
const { Vars, Var, Doc } = require('./query/woqlDoc');
78
/**
89
* @license Apache Version 2
@@ -46,7 +47,7 @@ WOQL.using = function (refPath, subquery) {
4647
/**
4748
* Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
4849
* @param {string} comment - text comment
49-
* @param {WOQLQuery} subquery - query that is "commented out"
50+
* @param {WOQLQuery} [subquery] - query that is "commented out"
5051
* @returns {WOQLQuery}
5152
*/
5253
WOQL.comment = function (comment, subquery) {
@@ -187,7 +188,7 @@ WOQL.from = function (graphRef, query) {
187188
/**
188189
* Specifies the graph resource to write the contained query into
189190
* @param {typedef.GraphRef} graphRef- A valid graph resource identifier string
190-
* @param {WOQLQuery} subquery - The query which will be written into the graph
191+
* @param {WOQLQuery} [subquery] - The query which will be written into the graph
191192
* @returns {WOQLQuery} A WOQLQuery which will be written into the graph in question
192193
* @example
193194
* //Subq is an argument or a chained query
@@ -1241,7 +1242,7 @@ WOQL.json = function (JSON_LD) {
12411242
* const query = WOQL.lib().branches()
12421243
*/
12431244
WOQL.lib = function () {
1244-
return new WOQLQuery().lib();
1245+
return new WOQLLibrary();
12451246
};
12461247

12471248
/**

lib/woqlClient.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const DispatchRequest = require('./dispatchRequest');
1111
const ErrorMessage = require('./errorMessage');
1212
const ConnectionConfig = require('./connectionConfig');
1313
const WOQL = require('./woql');
14-
const WOQLQuery = require('./query/woqlBuilder');
14+
const WOQLQuery = require('./query/woqlCore');
1515

1616
/**
1717
* @license Apache Version 2
@@ -1199,6 +1199,8 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
11991199
delete params.query;
12001200
}
12011201
// if query we are send a get with a payload
1202+
console.log(this.connectionConfig.documentURL(params));
1203+
12021204
if (queryDoc) {
12031205
return this.dispatch(
12041206
CONST.QUERY_DOCUMENT,

0 commit comments

Comments
 (0)