Skip to content

Commit ad593f9

Browse files
Type last (#241)
* review table * review woql for typescript * Apply docs changes * review type declaration * review types definition * Apply docs changes * review types definition * review types definition Co-authored-by: Francesca-Bit <[email protected]> Co-authored-by: Francesca-Bit <[email protected]>
1 parent 0853c24 commit ad593f9

File tree

12 files changed

+863
-408
lines changed

12 files changed

+863
-408
lines changed

docs/api/woql.md

Lines changed: 156 additions & 154 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable global-require */
2-
const Vars = require('./lib/query/woqlDoc');
2+
const { Var, Vars, Doc } = require('./lib/query/woqlDoc');
33
const WOQLClient = require('./lib/woqlClient');
44
const UTILS = require('./lib/utils');
55
const View = require('./lib/viewer/woqlView');
@@ -9,8 +9,11 @@ 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 = {
15+
Var,
16+
Doc,
1417
Vars,
1518
WOQLClient,
1619
UTILS,
@@ -21,4 +24,5 @@ module.exports = {
2124
WOQLGraph,
2225
axiosInstance,
2326
AccessControl,
27+
WOQLQuery,
2428
};

lib/query/woqlBuilder.js

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,33 @@
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+
// eslint-disable-next-line no-useless-constructor
27+
constructor(query) {
28+
super(query);
29+
}
30+
}
2231

32+
// WOQLQuery.prototype.counter = 1;
33+
/**
34+
* @param {typedef.GraphRef} [Graph] - the resource identifier of a graph possible
35+
* @param {string|Var} [Subj] - The IRI of a triple’s subject or a variable
36+
* @param {string|Var} [Pred] - The IRI of a property or a variable
37+
* @param {string|Var} [Obj] - The IRI of a node or a variable, or a literal
38+
* @returns {WOQLQuery} - A WOQLQuery which contains the pattern matching expression
39+
*/
2340
/**
2441
* Simple composite functions which produce WOQL queries
2542
*/
@@ -34,35 +51,77 @@ WOQLQuery.prototype.star = function (Graph, Subj, Pred, Obj) {
3451
return this.triple(Subj, Pred, Obj);
3552
};
3653

54+
/**
55+
* @param {string|Var} [Subj] - The IRI of a triple’s subject or a variable
56+
* @param {string|Var} [Pred] - The IRI of a property or a variable
57+
* @param {string|Var} [Obj] - The IRI of a node or a variable, or a literal
58+
* @param {typedef.GraphRef} [Graph] - the resource identifier of a graph possible
59+
* @returns {WOQLQuery} - A WOQLQuery which contains the pattern matching expression
60+
*/
61+
3762
WOQLQuery.prototype.all = function (Subj, Pred, Obj, Graph) {
3863
return this.star(Graph, Subj, Pred, Obj);
3964
};
4065

41-
WOQLQuery.prototype.lib = function () {
66+
/* WOQLQuery.prototype.lib = function () {
4267
return new WOQLLibrary();
43-
};
68+
}; */
69+
70+
/**
71+
* @param {string} s
72+
* @returns {object}
73+
* @example
74+
*/
4475

4576
WOQLQuery.prototype.string = function (s) {
4677
return { '@type': 'xsd:string', '@value': String(s) };
4778
};
4879

80+
/**
81+
* @param {boolean} tf
82+
* @returns {object}
83+
* @example
84+
*/
85+
4986
WOQLQuery.prototype.boolean = function (tf) {
5087
tf = tf || false;
5188
return this.literal(tf, 'boolean');
5289
};
5390

91+
/**
92+
* @param {any} s
93+
* @param {string} t
94+
* @returns {object}
95+
* @example
96+
*/
5497
WOQLQuery.prototype.literal = function (s, t) {
5598
t = t.indexOf(':') === -1 ? `xsd:${t}` : t;
5699
return { '@type': t, '@value': s };
57100
};
58101

102+
/**
103+
* @param {string} s
104+
* @returns {object}
105+
* @example
106+
*/
107+
59108
WOQLQuery.prototype.iri = function (s) {
60109
return {
61110
'@type': 'NodeValue',
62111
node: s,
63112
};
64113
};
65114

115+
/**
116+
* Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the
117+
* new one (Subject, Predicate, newObjValue)
118+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
119+
* @param {string|Var} predicate - The IRI of a property or a variable
120+
* @param {string|Var} newObjValue - The value to update or a literal
121+
* @param {string|Var} oldObjValue - The old value of the object
122+
* @returns {WOQLQuery} A WOQLQuery which contains the a Update Triple Statement
123+
*/
124+
66125
WOQLQuery.prototype.update_triple = function (subject, predicate, new_object, old_object) {
67126
const tmp_name = old_object || `v:AnyObject__${this.counter += 1}`;
68127
return this.and(
@@ -104,7 +163,7 @@ WOQLQuery.prototype.update_quad = function (subject, predicate, new_object, grap
104163

105164
/**
106165
* Removes all triples from a graph
107-
* @param {string} g - optional graph resource identifier
166+
* @param {string} [g] - optional graph resource identifier
108167
*/
109168

110169
WOQLQuery.prototype.nuke = function (g) {
@@ -114,6 +173,16 @@ WOQLQuery.prototype.nuke = function (g) {
114173
return this.triple('v:A', 'v:B', 'v:C').delete_triple('v:A', 'v:B', 'v:C');
115174
};
116175

176+
/**
177+
*
178+
* @param {string|Var} node - The IRI of a node or a variable containing an IRI which will
179+
* be the subject of the builder functions
180+
* @param {typedef.FuntionType} [type] - Optional type of builder function to build
181+
* (default is triple)
182+
* @returns {WOQLQuery} - A WOQLQuery which contains the partial Node pattern matching expression
183+
* @example
184+
*/
185+
117186
WOQLQuery.prototype.node = function (node, type) {
118187
type = type || false;
119188
if (type === 'add_quad') type = 'AddTriple';
@@ -151,6 +220,13 @@ WOQLQuery.prototype._set_context = function (ctxt) {
151220
return this;
152221
};
153222

223+
/**
224+
* @param {string|Var} id - IRI string or variable containing
225+
* @param {string|Var} type - IRI string or variable containing the IRI of the
226+
* @param {typedef.GraphRef} [refGraph] - Optional Graph resource identifier
227+
* @returns {WOQLQuery} A WOQLQuery which contains the insert expression
228+
*/
229+
154230
WOQLQuery.prototype.insert = function (id, type, refGraph) {
155231
refGraph = refGraph || (this.triple_builder_context ? this.triple_builder_context.graph : false);
156232
if (refGraph) {

lib/query/woqlCore.js

Lines changed: 52 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,57 @@ 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+
triple_builder_context = {};
54+
55+
query = null;
56+
57+
counter = 1;
58+
59+
errors = [];
60+
61+
cursor = {};
62+
63+
chain_ended = false;
64+
65+
contains_update = false;
66+
67+
// operators which preserve global paging
68+
paging_transitive_properties = ['select', 'from', 'start', 'when', 'opt', 'limit'];
69+
70+
update_operators = [
71+
'AddTriple',
72+
'DeleteTriple',
73+
'AddQuad',
74+
'DeleteQuad',
75+
'InsertDocument',
76+
'DeleteDocument',
77+
'UpdateDocument',
78+
];
79+
80+
vocab = this.loadDefaultVocabulary();
81+
82+
// object used to accumulate triples from fragments to support usage like node("x").label("y");
83+
tripleBuilder = false;
84+
/**
85+
* defines the internal functions of the woql query object - the
86+
* language API is defined in WOQLQuery
87+
* @module WOQLQuery
88+
* @constructor
89+
* @param {object} [query] json-ld query for initialisation
90+
* @returns {WOQLQuery}
91+
*/
92+
93+
constructor(query) {
94+
this.query = query || {};
95+
// this.errors = [];
96+
this.cursor = this.query;
97+
98+
// eslint-disable-next-line no-constructor-return
99+
return this;
100+
}
50101
}
51102

52103
/**

lib/query/woqlDoc.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,37 @@ function convert(obj) {
6666
}
6767
}
6868

69+
/**
70+
* @param {string} name
71+
* @returns
72+
*/
6973
function Var(name) {
7074
this.name = name;
7175
}
7276

77+
/**
78+
* @param {object} name
79+
* @returns {object}
80+
*/
7381
function Doc(obj) {
7482
this.doc = obj;
7583
this.encoded = convert(obj);
84+
return this.encoded;
7685
}
7786

87+
/**
88+
* @param {...string} varNames
89+
* @returns {object<Var>}
90+
*/
7891
function Vars(...args) {
92+
const varObj = {};
7993
for (let i = 0, j = arguments.length; i < j; i += 1) {
8094
const argumentName = args[i];
81-
this[argumentName] = new Var(argumentName);
95+
96+
// this[argumentName] = new Var(argumentName);
97+
varObj[argumentName] = new Var(argumentName);
8298
}
99+
return varObj;
83100
}
84101

85102
module.exports = { Vars, Var, Doc };

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
/**

0 commit comments

Comments
 (0)