Skip to content

Commit ecc5aef

Browse files
committed
Merge branch 'vars_like_python' of https://github.com/terminusdb/terminusdb-client-js into vars_like_python
2 parents 7316257 + 70d0a08 commit ecc5aef

File tree

8 files changed

+57
-21
lines changed

8 files changed

+57
-21
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
with:
2222
source_folder: 'docs/api/.'
2323
destination_repo: 'terminusdb/terminusdb-docs'
24-
destination_folder: 'index/terminusx-db/reference-guides/javascript-client-reference'
24+
destination_folder: 'guides/reference-guides/javascript-client-reference'
2525
destination_base_branch: 'main'
2626
destination_head_branch: ${{ env.BRANCH_NAME }}
2727
user_email: '[email protected]'
2828
user_name: 'Neelterminusdb'
29-
pull_request_reviewers: 'mark-terminusdb'
29+
pull_request_reviewers: 'mark-terminusdb'

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ graph all through a simple document API.
2222
[terminusdb-docs]: https://terminusdb.com/docs/
2323
[terminusdb-repo]: https://github.com/terminusdb/terminusdb
2424

25-
**TerminusX** is a self-service data platform that allows you to build, deploy,
26-
execute, monitor, and share versioned data products. It is built on TerminusDB.
27-
TerminusX is in public beta and you can [sign up now][dashboard].
25+
**TerminusX** TerminusX is TerminusDB as a service. SOC 2 certified hosting. Build your beta and get to market fast. Scale up and deploy your own instance. [Sign up now][dashboard].
2826

2927
[dashboard]: https://dashboard.terminusdb.com/
3028

@@ -71,7 +69,7 @@ it to your sources, and use that in the `<script>` instead.
7169
This example creates a simple dataProduct, starting to create a database model the schema
7270
and insert a simple document
7371

74-
For the [full Documentation][terminusdb-client-js-docs]
72+
For the [full Documentation](https://terminusdb.com/docs/guides/reference-guides/javascript-client-reference)
7573

7674
```javascript
7775
const TerminusClient = require("@terminusdb/terminusdb-client");

lib/query/woqlCore.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// /@ts-check
1515
const UTILS = require('../utils');
1616
const WOQLPrinter = require('./woqlPrinter');
17-
const { Var, Doc } = require('./woqlDoc');
17+
const { Var, Vars, Doc } = require('./woqlDoc');
1818

1919
/**
2020
* defines the internal functions of the woql query object - the
@@ -709,9 +709,9 @@ function getClauseAndRemainder(pat) {
709709

710710
function compilePredicate(pp, q) {
711711
if (pp.indexOf('<') !== -1 && pp.indexOf('>') !== -1) {
712-
let pred = pp.slice(1, pp.length - 1);
712+
const pred = pp.slice(1, pp.length - 1);
713713
// eslint-disable-next-line no-multi-assign,no-constant-condition
714-
const cleaned = (pred = '*' ? 'owl:topObjectProperty' : q.cleanPathPredicate(pred));
714+
const cleaned = pred === '.' ? null : q.cleanPathPredicate(pred);
715715
return {
716716
'@type': 'PathOr',
717717
or: [{
@@ -725,18 +725,15 @@ function compilePredicate(pp, q) {
725725
};
726726
} if (pp.indexOf('<') !== -1) {
727727
const pred = pp.slice(1, pp.length);
728-
// let cleaned = pred === '*' ? 'owl:topObjectProperty' : q.cleanPathPredicate(pred)
729-
const cleaned = q.cleanPathPredicate(pred);
728+
const cleaned = pred === '.' ? null : q.cleanPathPredicate(pred);
730729
return { '@type': 'InversePathPredicate', predicate: cleaned };
731730
} if (pp.indexOf('>') !== -1) {
732731
const pred = pp.slice(0, pp.length - 1);
733-
// let cleaned = pred === '*' ? 'owl:topObjectProperty' : q.cleanPathPredicate(pred)
734-
const cleaned = q.cleanPathPredicate(pred);
732+
const cleaned = pred === '.' ? null : q.cleanPathPredicate(pred);
735733
return { '@type': 'PathPredicate', predicate: cleaned };
736734
}
737-
// let pred = pp === '*' ? 'owl:topObjectProperty' : q.cleanPathPredicate(pp)
738-
const pred = q.cleanPathPredicate(pp);
739-
return { '@type': 'PathPredicate', predicate: pred };
735+
const cleaned = pp === '.' ? null : q.cleanPathPredicate(pp);
736+
return { '@type': 'PathPredicate', predicate: cleaned };
740737
}
741738

742739
/**
@@ -843,6 +840,8 @@ function copyJSON(orig, rollup) {
843840
}
844841
}
845842
nuj[k] = nupart;
843+
} else if (part === null) {
844+
// do nothing
846845
} else if (typeof part === 'object') {
847846
const q = copyJSON(part, rollup);
848847
if (!q || !UTILS.empty(q)) nuj[k] = q;

lib/query/woqlDoc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,11 @@ function Doc(obj) {
7474
this.doc = obj;
7575
this.encoded = convert(obj);
7676
}
77-
module.exports = { Var, Doc };
77+
78+
function Vars() {
79+
for(let k of arguments){
80+
this[k] = new Var(k)
81+
}
82+
}
83+
84+
module.exports = { Vars, Var, Doc };

lib/query/woqlPrinter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ WOQLPrinter.prototype.decompilePathPattern = function (pstruct) {
389389
// eslint-disable-next-line default-case
390390
switch (t) {
391391
case 'InversePathPredicate':
392-
return `<${pstruct.predicate}`;
392+
return pstruct.predicate ? `<${pstruct.predicate}` : '<.';
393393
case 'PathPredicate':
394-
return pstruct.predicate;
394+
return pstruct.predicate ? `${pstruct.predicate}` : '.';
395395
case 'PathPlus':
396396
var next = pstruct.plus;
397397
if (Array.isArray(next)) next = next[0];

lib/query/woqlQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// /@ts-check
1313
// WOQLQuery
1414
const WOQLQuery = require('./woqlCore');
15-
const { Var, Doc } = require('./woqlDoc');
15+
const { Var, Vars, Doc } = require('./woqlDoc');
1616

1717
// I HAVE TO REVIEW THE Inheritance and the prototype chain
1818
/* class WOQLQuery extends WOQLCore {

lib/woql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// /@ts-check
44
// I HAVE TO REVIEW THE Inheritance and the prototype chain
55
const WOQLQuery = require('./query/woqlBuilder');
6-
const { Var, Doc } = require('./query/woqlDoc');
6+
const { Vars, Var, Doc } = require('./query/woqlDoc');
77
/**
88
* @license Apache Version 2
99
* @module WOQL

test/woqlPathquery.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,38 @@ describe('woql path query and path query prettyprint', () => {
2727
expect(query.prettyPrint()).to.eql('WOQL.path("v:X", "hop", "v:Y", "v:Path")');
2828
});
2929

30+
it('simple any path query', () => {
31+
const query = WOQL.path('v:X', '.*,name', 'v:Y');
32+
const json = {
33+
'@type': 'Path',
34+
subject: {
35+
'@type': 'NodeValue',
36+
variable: 'X',
37+
},
38+
pattern: {
39+
'@type': "PathSequence",
40+
'sequence': [
41+
{
42+
'@type': "PathStar",
43+
'star': {
44+
'@type': "PathPredicate"
45+
}
46+
},
47+
{
48+
'@type': "PathPredicate",
49+
'predicate' : "name"
50+
}
51+
]
52+
},
53+
object: {
54+
'@type': 'Value',
55+
variable: 'Y',
56+
}
57+
};
58+
expect(query.json()).to.eql(json);
59+
expect(query.prettyPrint()).to.eql('WOQL.path("v:X", "(.*),name", "v:Y")');
60+
});
61+
3062
it('test plus directed path query', () => {
3163
const query = WOQL.path('v:X', '<hop+', 'v:Y', 'v:Path');
3264
const json = {

0 commit comments

Comments
 (0)