Skip to content

Commit 7163592

Browse files
committed
2 parents 47daf38 + 8e064e1 commit 7163592

File tree

11 files changed

+679
-391
lines changed

11 files changed

+679
-391
lines changed

RELEASE_NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
# TerminusDB Client v10.0.24
3+
4+
## Fixes 🛠
5+
6+
* Review WOQL typescript definitions
7+
18
# TerminusDB Client v10.0.22
29

310
## New 🚀

docs/api/woql.md

Lines changed: 150 additions & 148 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 3 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');
@@ -12,6 +12,8 @@ const AccessControl = require('./lib/accessControl');
1212
const WOQLQuery = require('./lib/query/woqlBuilder');
1313

1414
module.exports = {
15+
Var,
16+
Doc,
1517
Vars,
1618
WOQLClient,
1719
UTILS,

lib/query/woqlBuilder.js

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ const WOQLQueryExt = require('./woqlQuery');
2323
// const WOQLLibrary = require('./woqlLibrary');
2424

2525
class WOQLQuery extends WOQLQueryExt {
26-
counter = 1;
27-
2826
// eslint-disable-next-line no-useless-constructor
2927
constructor(query) {
3028
super(query);
3129
}
3230
}
3331

3432
// WOQLQuery.prototype.counter = 1;
35-
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+
*/
3640
/**
3741
* Simple composite functions which produce WOQL queries
3842
*/
@@ -47,6 +51,14 @@ WOQLQuery.prototype.star = function (Graph, Subj, Pred, Obj) {
4751
return this.triple(Subj, Pred, Obj);
4852
};
4953

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+
5062
WOQLQuery.prototype.all = function (Subj, Pred, Obj, Graph) {
5163
return this.star(Graph, Subj, Pred, Obj);
5264
};
@@ -55,27 +67,61 @@ WOQLQuery.prototype.all = function (Subj, Pred, Obj, Graph) {
5567
return new WOQLLibrary();
5668
}; */
5769

70+
/**
71+
* @param {string} s
72+
* @returns {object}
73+
* @example
74+
*/
75+
5876
WOQLQuery.prototype.string = function (s) {
5977
return { '@type': 'xsd:string', '@value': String(s) };
6078
};
6179

80+
/**
81+
* @param {boolean} tf
82+
* @returns {object}
83+
* @example
84+
*/
85+
6286
WOQLQuery.prototype.boolean = function (tf) {
6387
tf = tf || false;
6488
return this.literal(tf, 'boolean');
6589
};
6690

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

102+
/**
103+
* @param {string} s
104+
* @returns {object}
105+
* @example
106+
*/
107+
72108
WOQLQuery.prototype.iri = function (s) {
73109
return {
74110
'@type': 'NodeValue',
75111
node: s,
76112
};
77113
};
78114

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+
79125
WOQLQuery.prototype.update_triple = function (subject, predicate, new_object, old_object) {
80126
const tmp_name = old_object || `v:AnyObject__${this.counter += 1}`;
81127
return this.and(
@@ -117,7 +163,7 @@ WOQLQuery.prototype.update_quad = function (subject, predicate, new_object, grap
117163

118164
/**
119165
* Removes all triples from a graph
120-
* @param {string} g - optional graph resource identifier
166+
* @param {string} [g] - optional graph resource identifier
121167
*/
122168

123169
WOQLQuery.prototype.nuke = function (g) {
@@ -127,6 +173,16 @@ WOQLQuery.prototype.nuke = function (g) {
127173
return this.triple('v:A', 'v:B', 'v:C').delete_triple('v:A', 'v:B', 'v:C');
128174
};
129175

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+
130186
WOQLQuery.prototype.node = function (node, type) {
131187
type = type || false;
132188
if (type === 'add_quad') type = 'AddTriple';
@@ -164,6 +220,13 @@ WOQLQuery.prototype._set_context = function (ctxt) {
164220
return this;
165221
};
166222

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+
167230
WOQLQuery.prototype.insert = function (id, type, refGraph) {
168231
refGraph = refGraph || (this.triple_builder_context ? this.triple_builder_context.graph : false);
169232
if (refGraph) {

lib/query/woqlCore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ const { Var, Vars, Doc } = require('./woqlDoc');
5050
} */
5151

5252
class WOQLQuery {
53+
triple_builder_context = {};
54+
5355
query = null;
5456

57+
counter = 1;
58+
5559
errors = [];
5660

5761
cursor = {};

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 };

0 commit comments

Comments
 (0)