Skip to content

Commit 2461a43

Browse files
committed
Make it possible to run mkdocs on the prefixes too
1 parent c05a77d commit 2461a43

File tree

7 files changed

+142
-39
lines changed

7 files changed

+142
-39
lines changed

lib/query/woqlCore.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ const { Var, Vars, Doc } = require('./woqlDoc');
2020
const typedef = require('../typedef');
2121

2222
/**
23-
* @typedef {import('../typedef').WOQLJson} WOQLJson
23+
* @typedef {Object} WOQLJson - JSON-LD representation of a WOQL query
24+
* @property {string} @type - The WOQL operation type
25+
* @property {*} [subject] - Subject for triple patterns
26+
* @property {*} [predicate] - Predicate for triple patterns
27+
* @property {*} [object] - Object for triple patterns
28+
* @property {WOQLJson[]} [and] - Array of queries for 'And' operations
29+
* @property {WOQLJson[]} [or] - Array of queries for 'Or' operations
30+
* @property {WOQLJson} [query] - Nested query
31+
* @property {string[]} [variables] - Variable list for 'Select' operations
32+
* @property {string} [graph] - Graph identifier
33+
* @property {*} [consequent] - Consequent for path queries
34+
* @property {string} [path_pattern] - Pattern for path queries
2435
*/
2536

2637
/**
@@ -414,12 +425,11 @@ WOQLQuery.prototype.cleanObject = function (o, t) {
414425
}
415426
obj.list = res;
416427
} else if (typeof o === 'object' && o) {
417-
if (typeof o['@value'] !== 'undefined') obj.data = o;
418-
else return o;
419-
// eslint-disable-next-line no-dupe-else-if
420-
} else if (typeof o === 'boolean') {
421-
t = t || 'xsd:boolean';
422-
obj['woql:datatype'] = this.jlt(o, t);
428+
if (typeof o['@value'] !== 'undefined') {
429+
obj.data = o;
430+
} else {
431+
return o;
432+
}
423433
}
424434
return obj;
425435
};
@@ -428,9 +438,11 @@ WOQLQuery.prototype.cleanDataValue = function (o, t) {
428438
const obj = { '@type': 'DataValue' };
429439
if (o instanceof Var) {
430440
return this.expandDataVariable(o);
431-
} if (o instanceof Doc) {
441+
}
442+
if (o instanceof Doc) {
432443
return o.encoded;
433-
} if (typeof o === 'string') {
444+
}
445+
if (typeof o === 'string') {
434446
if (o.indexOf('v:') !== -1) {
435447
return this.expandDataVariable(o);
436448
}

lib/query/woqlLibrary.js

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,80 @@
33
const WOQLQuery = require('./woqlBuilder');
44

55
/**
6-
* @typedef {import('./woqlBuilder')} WOQLQuery
6+
* @typedef {Object} WOQLQuery - WOQL Query Builder class
7+
* @property {function} triple - Add a triple pattern
8+
* @property {function} and - Logical AND
9+
* @property {function} or - Logical OR
10+
* @property {function} select - Select variables
11+
* @property {function} ask - Ask query
12+
* @property {function} limit - Limit results
13+
* @property {function} offset - Offset results
14+
* @property {function} start - Start query
15+
* @property {function} path - Path query
16+
* @property {function} subquery - Subquery
17+
* @property {function} from - Graph specifier
18+
* @property {function} eq - Equality
19+
* @property {function} not - Negation
20+
* @property {function} greaterThan - Greater than
21+
* @property {function} lessThan - Less than
22+
* @property {function} greaterThanOrEqual - Greater than or equal
23+
* @property {function} lessThanOrEqual - Less than or equal
24+
* @property {function} like - String pattern matching
25+
* @property {function} plus - Addition
26+
* @property {function} minus - Subtraction
27+
* @property {function} times - Multiplication
28+
* @property {function} divide - Division
29+
* @property {function} count - Count aggregation
30+
* @property {function} sum - Sum aggregation
31+
* @property {function} min - Minimum aggregation
32+
* @property {function} max - Maximum aggregation
33+
* @property {function} avg - Average aggregation
34+
* @property {function} groupBy - Group by
35+
* @property {function} orderBy - Order by
36+
* @property {function} asc - Ascending order
37+
* @property {function} desc - Descending order
38+
* @property {function} json - JSON object
39+
* @property {function} id - IRI
40+
* @property {function} string - String literal
41+
* @property {function} datetime - DateTime literal
42+
* @property {function} date - Date literal
43+
* @property {function} time - Time literal
44+
* @property {function} boolean - Boolean literal
45+
* @property {function} integer - Integer literal
46+
* @property {function} decimal - Decimal literal
47+
* @property {function} double - Double literal
48+
* @property {function} value - Value literal
49+
* @property {function} var - Variable
50+
* @property {function} v - Variable shorthand
51+
* @property {function} doc - Document
52+
* @property {function} class - Class
53+
* @property {function} property - Property
54+
* @property {function} comment - Comment
55+
* @property {function} label - Label
56+
* @property {function} prefix - Prefix
57+
* @property {function} using - Using
58+
* @property {function} optional - Optional
59+
* @property {function} union - Union
60+
* @property {function} filter - Filter
61+
* @property {function} bind - Bind
62+
* @property {function} exists - Exists
63+
* @property {function} notExists - Not exists
64+
* @property {function} graph - Graph
65+
* @property {function} named - Named graph
66+
* @property {function} values - Values
67+
* @property {function} minus - Minus
68+
* @property {function} service - Service
69+
* @property {function} load - Load
70+
* @property {function} clear - Clear
71+
* @property {function} drop - Drop
72+
* @property {function} add - Add
73+
* @property {function} move - Move
74+
* @property {function} copy - Copy
75+
* @property {function} insert - Insert
76+
* @property {function} delete - Delete
77+
* @property {function} modify - Modify
78+
* @property {function} construct - Construct
79+
* @property {function} describe - Describe
780
*/
881

982
/**

lib/query/woqlQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ WOQLQuery.prototype.select = function (...varNames) {
336336
* Parameters with null values are local-only variables.
337337
*
338338
* @param {object} paramSpec - Object mapping parameter names to values (or null for local vars)
339-
* @returns {[function, object]} Tuple of [localized function, variables object]
339+
* @returns {LocalizeResult} Tuple of [localized function, variables object]
340340
* @example
341341
* const [localized, v] = WOQL.localize({ consSubject, valueVar, last_cell: null });
342342
* return localized(

lib/typedef.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,23 @@ const { ACTIONS } = Utils.ACTIONS;
226226
* Additional properties depend on the specific WOQL operation type
227227
*/
228228

229-
module.exports = {};
229+
/**
230+
* @typedef {Object} WOQLQuery - WOQL Query Builder class
231+
*/
232+
233+
/**
234+
* Result from WOQL.localize() function - a two-element array [localizedFn, vars]
235+
* @typedef {Object} LocalizeResult
236+
* @property {function(WOQLQuery=): WOQLQuery} 0 - Localized function that wraps queries
237+
* @property {Object.<string, Var>} 1 - Variables object with unique names
238+
*/
239+
240+
// eslint-disable-next-line no-unused-vars
241+
const WOQLJson = {};
242+
// eslint-disable-next-line no-unused-vars
243+
const WOQLQuery = {};
244+
245+
module.exports = {
246+
WOQLJson,
247+
WOQLQuery,
248+
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@terminusdb/terminusdb-client",
3-
"version": "12.0.1",
3+
"version": "12.0.3",
44
"description": "TerminusDB client library",
55
"main": "index.js",
66
"types": "./dist/typescript/index.d.ts",

test/woql.spec.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,29 @@ describe('woql queries', () => {
4848
});
4949

5050
it('check the start method', () => {
51-
const woqlObject = WOQL.limit(10).start(0);
52-
53-
/* const jsonObj={"@type": "woql:Limit",
54-
"woql:limit": {
55-
"@type": "woql:DataValue",
56-
"woql:datatype": {
57-
"@type": "xsd:nonNegativeInteger",
58-
"@value": 10
59-
}
60-
},
61-
"woql:query": {
62-
"@type": "woql:Start",
63-
"woql:start": {
64-
"@type": "woql:DataValue",
65-
"woql:datatype": {
66-
"@type": "xsd:nonNegativeInteger",
67-
"@value": 0
68-
}
69-
},
70-
"woql:query": {}
71-
}
72-
} */
73-
74-
// expect(woqlObject.json()).to.eql({});
51+
const woqlObject = WOQL.start(10).limit(5).eq('v:X', 'v:Y');
52+
53+
const expectedJson = {
54+
'@type': 'Start',
55+
start: 10,
56+
query: {
57+
'@type': 'Limit',
58+
limit: 5,
59+
query: {
60+
'@type': 'Equals',
61+
left: {
62+
'@type': 'Value',
63+
variable: 'X',
64+
},
65+
right: {
66+
'@type': 'Value',
67+
variable: 'Y',
68+
},
69+
},
70+
},
71+
};
72+
73+
expect(woqlObject.json()).to.eql(expectedJson);
7574
});
7675

7776
it('check the not method', () => {

0 commit comments

Comments
 (0)