Skip to content

Commit aab0461

Browse files
committed
Merge branch 'issue/325-literal-value-zero' of ssh://github.com/hoijnet/terminusdb-client-js into issue/325-literal-value-zero
2 parents 7885836 + 3882083 commit aab0461

20 files changed

+2866
-3404
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ jobs:
2828
if: needs.skip_if_running.outputs.skip != 'true'
2929

3030
steps:
31-
- uses: actions/checkout@v2
32-
- uses: actions/setup-node@v1
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-node@v4
3333
with:
34-
node-version: 14
34+
node-version: 18
3535
- name: Run terminusdb server
36-
run: docker run --detach --publish 127.0.0.1:6363:6363 terminusdb/terminusdb-server:dev && sleep 3
36+
run: |
37+
docker run --detach --publish 127.0.0.1:6363:6363 terminusdb/terminusdb-server:dev && sleep 10
38+
docker ps
39+
netstat -an |grep 6363
3740
- name: Install, build and test
3841
run: |
3942
npm ci

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1414
- name: Clone JSDoc template
1515
run: git clone https://github.com/terminusdb-labs/jsdoc-terminusdb-template.git
1616
- name: Run NPM Install

.github/workflows/production.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v4
1414
- name: Use Node.js ${{ matrix.node-version }}
1515
uses: actions/setup-node@v1
1616
with:
17-
node-version: 14
17+
node-version: 18
1818
registry-url: 'https://registry.npmjs.org'
1919
- run: npm install
2020
- run: npm run build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
and document store. It allows you to link JSON documents in a powerful knowledge
1919
graph all through a simple document API.
2020

21-
[terminusdb]: https://terminusdb.com/
22-
[terminusdb-docs]: https://terminusdb.com/docs/
21+
[terminusdb]: https://terminusdb.org/
22+
[terminusdb-docs]: https://terminusdb.org/docs/
2323
[terminusdb-repo]: https://github.com/terminusdb/terminusdb
2424

2525
**TerminusCMS** is a [headless content management system](https://terminusdb.com/terminuscms/) for complex enviroments. Try it out for yourself, it's free to get started with generous limits. Clone a demo project to play around. [Sign up][dashboard].

integration_tests/create_database.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { DbDetails, DocParamsGet } from '../dist/typescript/lib/typedef';
77
import schemaJson from './persons_schema'
88
//console.log(typeof schemaJson)
99

10-
let client : WOQLClient //= new WOQLClient('http://localhost:6363');
10+
let client : WOQLClient //= new WOQLClient('http://127.0.0.1:6363');
1111

1212
beforeAll(() => {
13-
client = new WOQLClient("http://localhost:6363",{ user: 'admin', organization: 'admin', key: 'root' })
13+
client = new WOQLClient("http://127.0.0.1:6363",{ user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
1414
});
1515

1616
const db01 = 'db__test';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@ts-check
2+
import { describe, expect, test, beforeAll } from '@jest/globals';
3+
import { WOQLClient, WOQL } from '../index.js';
4+
import { DbDetails } from '../dist/typescript/lib/typedef.js';
5+
import { Vars } from '../lib/woql.js';
6+
7+
let client: WOQLClient //= new WOQLClient('http://127.0.0.1:6363');
8+
const db01 = 'db__test_woql_arithmetic';
9+
10+
beforeAll(() => {
11+
client = new WOQLClient("http://127.0.0.1:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
12+
client.db(db01);
13+
});
14+
15+
16+
describe('Tests for woql arithmetic', () => {
17+
test('Create a database', async () => {
18+
const dbObj: DbDetails = { label: db01, comment: 'add db', schema: true }
19+
const result = await client.createDatabase(db01, dbObj);
20+
//woqlClient return only the data no status
21+
expect(result["@type"]).toEqual("api:DbCreateResponse");
22+
expect(result["api:status"]).toEqual("api:success");
23+
});
24+
25+
test('Test simple arithmetic with vars variables handling', async () => {
26+
let v = Vars("result");
27+
const query = WOQL.limit(100).eval(WOQL.times(2, 3), v.result);
28+
29+
const expectedJson = [{"result": {"@type": "xsd:decimal", "@value": 6}}];
30+
31+
const result = await client.query(query);
32+
expect(result?.bindings).toStrictEqual(expectedJson);
33+
});
34+
35+
test('Test simple arithmetic with string variable handling', async () => {
36+
const query = WOQL.limit(100).eval(WOQL.times(2, 3), "v:result");
37+
38+
const expectedJson = [{"result": {"@type": "xsd:decimal", "@value": 6}}];
39+
40+
const result = await client.query(query);
41+
expect(result?.bindings).toStrictEqual(expectedJson);
42+
});
43+
44+
test('Delete a database', async () => {
45+
const result = await client.deleteDatabase(db01);
46+
expect(result).toStrictEqual({ '@type': 'api:DbDeleteResponse', 'api:status': 'api:success' });
47+
});
48+
});

integration_tests/woql_client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import schemaJson from './persons_schema'
66
import { mock_employees_limit_1 } from './data/employees_limit1';
77
import fs from 'fs';
88

9-
let client: WOQLClient //= new WOQLClient('http://localhost:6363');
9+
let client: WOQLClient //= new WOQLClient('http://127.0.0.1:6363');
1010

1111
beforeAll(() => {
12-
client = new WOQLClient("http://localhost:6363", { user: 'admin', organization: 'admin', key: 'root' })
12+
client = new WOQLClient("http://127.0.0.1:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
1313
});
1414

1515
const db01 = 'db__test_woql';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ts-check
2+
import { describe, expect, test, beforeAll } from '@jest/globals';
3+
import { WOQLClient, WOQL, Vars } from '../index.js';
4+
import { DbDetails } from '../dist/typescript/lib/typedef.js';
5+
6+
let client: WOQLClient
7+
const db01 = 'db__test_woql_regression';
8+
9+
beforeAll(async () => {
10+
client = new WOQLClient("http://127.0.0.1:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
11+
client.db(db01);
12+
const dbObj: DbDetails = { label: db01, comment: 'add db', schema: true }
13+
await client.createDatabase(db01, dbObj);
14+
});
15+
16+
afterAll(async () => {
17+
await client.deleteDatabase(db01);
18+
});
19+
20+
describe('Tests for woql graph addressing', () => {
21+
it('should construct correct query for: from instance', async () => {
22+
const query = WOQL.from('instance').limit(10).eval(WOQL.plus(1, 1), 'v:result');
23+
24+
const expectedJson = [{ "result": { "@type": "xsd:decimal", "@value": 2 } }];
25+
26+
const result = await client.query(query);
27+
expect(result?.bindings).toStrictEqual(expectedJson);
28+
});
29+
30+
it('should construct correct query for: from schema', async () => {
31+
// This tests corresponds to issue #2077, with incorrect AST, now fixed
32+
// https://github.com/terminusdb/terminusdb/issues/2077
33+
let v = Vars("cls");
34+
const query = WOQL.from("schema")
35+
.triple(v.cls, "rdf:type", "sys:Class")
36+
const expectedJson = [];
37+
const result = await client.query(query);
38+
expect(result?.bindings).toStrictEqual(expectedJson);
39+
});
40+
41+
test('should construct correct query for: info', async () => {
42+
const result = await client.info();
43+
expect(result["@type"]).toStrictEqual("api:InfoResponse");
44+
});
45+
});

lib/accessControl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const typedef = require('./typedef');
3838
* eTFORUd.......")
3939
*
4040
* //connect with the base authentication this type of connection is only for the local installation
41-
* const accessContol = new AccessControl("http://localhost:6363",
41+
* const accessContol = new AccessControl("http://127.0.0.1:6363",
4242
* {organization:"my_team_name", user:"admin"
4343
* key:"mykey"})
4444
* accessControl.getOrgUsers().then(result=>{

lib/query/woqlQuery.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ const typedef = require('../typedef');
2929

3030
// I HAVE TO REVIEW THE Inheritance and the prototype chain
3131
class WOQLQuery extends WOQLCore {
32-
/**
33-
* defines the internal functions of the woql query object - the
34-
* language API is defined in WOQLQuery
35-
* @module WOQLQuery
36-
* @constructor
37-
* @param {object} [query] json-ld query for initialisation
38-
* @returns {WOQLQuery}
39-
*/
32+
/**
33+
* defines the internal functions of the woql query object - the
34+
* language API is defined in WOQLQuery
35+
* @module WOQLQuery
36+
* @constructor
37+
* @param {object} [query] json-ld query for initialisation
38+
* @returns {WOQLQuery}
39+
*/
4040

4141
/**
4242
* Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the
@@ -373,7 +373,7 @@ WOQLQuery.prototype.and = function (...subqueries) {
373373
const onevar = this.jobj(subqueries[i]);
374374
if (
375375
onevar['@type'] === 'And'
376-
&& onevar.and
376+
&& onevar.and
377377
) {
378378
for (let j = 0; j < onevar.and.length; j++) {
379379
const qjson = onevar.and[j];
@@ -421,17 +421,14 @@ WOQLQuery.prototype.or = function (...subqueries) {
421421
*/
422422

423423
WOQLQuery.prototype.from = function (graphRef, query) {
424-
// if (graph && graph === 'args')
425-
// return ['graph', 'query']
426424
if (this.cursor['@type']) this.wrapCursorWithAnd();
427425
this.cursor['@type'] = 'From';
428-
// FIXME: Fix the typeof check that should be graphRef, not graph
429-
if (!graphRef || typeof graph !== 'string') {
426+
if (!graphRef || typeof graphRef !== 'string') {
430427
return this.parameterError(
431428
'The first parameter to from must be a Graph Filter Expression (string)',
432429
);
433430
}
434-
this.cursor.graph = graphRef;
431+
this.cursor.graph = this.jlt(graphRef);
435432
return this.addSubQuery(query);
436433
};
437434

@@ -1489,7 +1486,7 @@ WOQLQuery.prototype.order_by = function (...orderedVarlist) {
14891486
);
14901487
}
14911488
const embedquery = typeof orderedVarlist[orderedVarlist.length - 1] === 'object'
1492-
&& orderedVarlist[orderedVarlist.length - 1].json
1489+
&& orderedVarlist[orderedVarlist.length - 1].json
14931490
? orderedVarlist.pop()
14941491
: false;
14951492

0 commit comments

Comments
 (0)