Skip to content

Commit 07c8754

Browse files
Merge pull request #319 from hoijnet/issue/318-fix-woql-from
Issue/318 fix woql from (fixes #318)
2 parents 79c28e1 + 1baa718 commit 07c8754

16 files changed

+108
-57
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

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: process.env.TDB_ADMIN_PASS ?? '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';

integration_tests/woql_arithmetic.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { WOQLClient, WOQL } from '../index.js';
44
import { DbDetails } from '../dist/typescript/lib/typedef.js';
55
import { Vars } from '../lib/woql.js';
66

7-
let client: WOQLClient //= new WOQLClient('http://localhost:6363');
7+
let client: WOQLClient //= new WOQLClient('http://127.0.0.1:6363');
88
const db01 = 'db__test_woql_arithmetic';
99

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

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: process.env.TDB_ADMIN_PASS ?? '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 & 14 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,16 +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-
if (!graphRef || typeof graph !== 'string') {
426+
if (!graphRef || typeof graphRef !== 'string') {
429427
return this.parameterError(
430428
'The first parameter to from must be a Graph Filter Expression (string)',
431429
);
432430
}
433-
this.cursor.graph = graphRef;
431+
this.cursor.graph = this.jlt(graphRef);
434432
return this.addSubQuery(query);
435433
};
436434

@@ -1487,7 +1485,7 @@ WOQLQuery.prototype.order_by = function (...orderedVarlist) {
14871485
);
14881486
}
14891487
const embedquery = typeof orderedVarlist[orderedVarlist.length - 1] === 'object'
1490-
&& orderedVarlist[orderedVarlist.length - 1].json
1488+
&& orderedVarlist[orderedVarlist.length - 1].json
14911489
? orderedVarlist.pop()
14921490
: false;
14931491

test/accessControl.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { expect } = require('chai');
22
const AccessControl = require('../lib/accessControl');
33

44
describe('AccessControl tests', () => {
5-
const startServerUrl = 'http://localhost:6363/';
5+
const startServerUrl = 'http://127.0.0.1:6363/';
66
const organization = 'admin';
77
const user = 'admin';
88
const key ='mykey'

0 commit comments

Comments
 (0)