Skip to content
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ jobs:
if: needs.skip_if_running.outputs.skip != 'true'

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18
- name: Run terminusdb server
run: docker run --detach --publish 127.0.0.1:6363:6363 terminusdb/terminusdb-server:dev && sleep 3
run: |
docker run --detach --publish 127.0.0.1:6363:6363 terminusdb/terminusdb-server:dev && sleep 10
docker ps
netstat -an |grep 6363
- name: Install, build and test
run: |
npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Clone JSDoc template
run: git clone https://github.com/terminusdb-labs/jsdoc-terminusdb-template.git
- name: Run NPM Install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/create_database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { DbDetails, DocParamsGet } from '../dist/typescript/lib/typedef';
import schemaJson from './persons_schema'
//console.log(typeof schemaJson)

let client : WOQLClient //= new WOQLClient('http://localhost:6363');
let client : WOQLClient //= new WOQLClient('http://127.0.0.1:6363');

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

const db01 = 'db__test';
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/woql_arithmetic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { WOQLClient, WOQL } from '../index.js';
import { DbDetails } from '../dist/typescript/lib/typedef.js';
import { Vars } from '../lib/woql.js';

let client: WOQLClient //= new WOQLClient('http://localhost:6363');
let client: WOQLClient //= new WOQLClient('http://127.0.0.1:6363');
const db01 = 'db__test_woql_arithmetic';

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

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/woql_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import schemaJson from './persons_schema'
import { mock_employees_limit_1 } from './data/employees_limit1';
import fs from 'fs';

let client: WOQLClient //= new WOQLClient('http://localhost:6363');
let client: WOQLClient //= new WOQLClient('http://127.0.0.1:6363');

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

const db01 = 'db__test_woql';
Expand Down
45 changes: 45 additions & 0 deletions integration_tests/woql_regression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//@ts-check
import { describe, expect, test, beforeAll } from '@jest/globals';
import { WOQLClient, WOQL, Vars } from '../index.js';
import { DbDetails } from '../dist/typescript/lib/typedef.js';

let client: WOQLClient
const db01 = 'db__test_woql_regression';

beforeAll(async () => {
client = new WOQLClient("http://127.0.0.1:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
client.db(db01);
const dbObj: DbDetails = { label: db01, comment: 'add db', schema: true }
await client.createDatabase(db01, dbObj);
});

afterAll(async () => {
await client.deleteDatabase(db01);
});

describe('Tests for woql graph addressing', () => {
it('should construct correct query for: from instance', async () => {
const query = WOQL.from('instance').limit(10).eval(WOQL.plus(1, 1), 'v:result');

const expectedJson = [{ "result": { "@type": "xsd:decimal", "@value": 2 } }];

const result = await client.query(query);
expect(result?.bindings).toStrictEqual(expectedJson);
});

it('should construct correct query for: from schema', async () => {
// This tests corresponds to issue #2077, with incorrect AST, now fixed
// https://github.com/terminusdb/terminusdb/issues/2077
let v = Vars("cls");
const query = WOQL.from("schema")
.triple(v.cls, "rdf:type", "sys:Class")
const expectedJson = [];
const result = await client.query(query);
expect(result?.bindings).toStrictEqual(expectedJson);
});

test('should construct correct query for: info', async () => {
const result = await client.info();
expect(result["@type"]).toStrictEqual("api:InfoResponse");
});
});
2 changes: 1 addition & 1 deletion lib/accessControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const typedef = require('./typedef');
* eTFORUd.......")
*
* //connect with the base authentication this type of connection is only for the local installation
* const accessContol = new AccessControl("http://localhost:6363",
* const accessContol = new AccessControl("http://127.0.0.1:6363",
* {organization:"my_team_name", user:"admin"
* key:"mykey"})
* accessControl.getOrgUsers().then(result=>{
Expand Down
26 changes: 12 additions & 14 deletions lib/query/woqlQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const typedef = require('../typedef');

// I HAVE TO REVIEW THE Inheritance and the prototype chain
class WOQLQuery extends WOQLCore {
/**
* defines the internal functions of the woql query object - the
* language API is defined in WOQLQuery
* @module WOQLQuery
* @constructor
* @param {object} [query] json-ld query for initialisation
* @returns {WOQLQuery}
*/
/**
* defines the internal functions of the woql query object - the
* language API is defined in WOQLQuery
* @module WOQLQuery
* @constructor
* @param {object} [query] json-ld query for initialisation
* @returns {WOQLQuery}
*/

/**
* Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the
Expand Down Expand Up @@ -373,7 +373,7 @@ WOQLQuery.prototype.and = function (...subqueries) {
const onevar = this.jobj(subqueries[i]);
if (
onevar['@type'] === 'And'
&& onevar.and
&& onevar.and
) {
for (let j = 0; j < onevar.and.length; j++) {
const qjson = onevar.and[j];
Expand Down Expand Up @@ -421,16 +421,14 @@ WOQLQuery.prototype.or = function (...subqueries) {
*/

WOQLQuery.prototype.from = function (graphRef, query) {
// if (graph && graph === 'args')
// return ['graph', 'query']
if (this.cursor['@type']) this.wrapCursorWithAnd();
this.cursor['@type'] = 'From';
if (!graphRef || typeof graph !== 'string') {
if (!graphRef || typeof graphRef !== 'string') {
return this.parameterError(
'The first parameter to from must be a Graph Filter Expression (string)',
);
}
this.cursor.graph = graphRef;
this.cursor.graph = this.jlt(graphRef);
return this.addSubQuery(query);
};

Expand Down Expand Up @@ -1487,7 +1485,7 @@ WOQLQuery.prototype.order_by = function (...orderedVarlist) {
);
}
const embedquery = typeof orderedVarlist[orderedVarlist.length - 1] === 'object'
&& orderedVarlist[orderedVarlist.length - 1].json
&& orderedVarlist[orderedVarlist.length - 1].json
? orderedVarlist.pop()
: false;

Expand Down
2 changes: 1 addition & 1 deletion test/accessControl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');
const AccessControl = require('../lib/accessControl');

describe('AccessControl tests', () => {
const startServerUrl = 'http://localhost:6363/';
const startServerUrl = 'http://127.0.0.1:6363/';
const organization = 'admin';
const user = 'admin';
const key ='mykey'
Expand Down
28 changes: 14 additions & 14 deletions test/connectionConfing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const { expect } = require('chai');
const ConnectionConfig = require('../lib/connectionConfig');

describe('connectionConfig tests', () => {
const startServerUrl = 'http://localhost:6363/';
const startServerUrl = 'http://127.0.0.1:6363/';
const startDBid = 'testDB';
const organization = 'admin';
const params = {
db: startDBid, organization, user: organization, key: 'myKey',
};
const connectionConfig = new ConnectionConfig(startServerUrl, params);

const dbURL = 'http://localhost:6363/api/db/admin/testDB';
const dbURL = 'http://127.0.0.1:6363/api/db/admin/testDB';

it('check get server URL', () => {
expect(connectionConfig.serverURL()).to.equal(startServerUrl);
Expand All @@ -22,7 +22,7 @@ describe('connectionConfig tests', () => {

it('check set branch', () => {
connectionConfig.setBranch('myBranch');
const queryURLBranch = 'http://localhost:6363/api/woql/admin/testDB/local/branch/myBranch';
const queryURLBranch = `${startServerUrl}api/woql/admin/testDB/local/branch/myBranch`;
/*
* the dbURL dosen't change
*/
Expand All @@ -33,7 +33,7 @@ describe('connectionConfig tests', () => {
it('check set refId', () => {
connectionConfig.setRef('gfhfjkflfgorpyuiioo');

const queryURL = 'http://localhost:6363/api/woql/admin/testDB/local/commit/gfhfjkflfgorpyuiioo';
const queryURL = `${startServerUrl}api/woql/admin/testDB/local/commit/gfhfjkflfgorpyuiioo`;

expect(connectionConfig.queryURL()).to.equal(queryURL);
});
Expand All @@ -42,17 +42,17 @@ describe('connectionConfig tests', () => {
* get the schema in owl turtle encoding
*/
it('check set class tripleUrl', () => {
const classTripleURL = 'http://localhost:6363/api/triples/admin/testDB/local/commit/gfhfjkflfgorpyuiioo/schema/main';
const classTripleURL = `${startServerUrl}api/triples/admin/testDB/local/commit/gfhfjkflfgorpyuiioo/schema/main`;

// console.log(JSON.stringify(connectionConfig.triplesURL(), null, 4));

expect(connectionConfig.triplesURL('schema')).to.equal(classTripleURL);
});

it('check remove the refCommit', () => {
const queryUrlBranch01 = 'http://localhost:6363/api/woql/admin/testDB/local/branch/myBranch';
// const queryFrameBranch01 = 'http://localhost:6363/api/frame/admin/testDB/local/branch/myBranch'
const queryTriplesBranch01 = 'http://localhost:6363/api/triples/admin/testDB/local/branch/myBranch/schema/main';
const queryUrlBranch01 = `${startServerUrl}api/woql/admin/testDB/local/branch/myBranch`;
// const queryFrameBranch01 = `${startServerUrl}api/frame/admin/testDB/local/branch/myBranch`
const queryTriplesBranch01 = `${startServerUrl}api/triples/admin/testDB/local/branch/myBranch/schema/main`;
/*
*remove the ref commit it come to the
*/
Expand All @@ -65,17 +65,17 @@ describe('connectionConfig tests', () => {
});

it('check set branch', () => {
const optimizeUrl = 'http://localhost:6363/api/optimize/admin/testDB/local/branch/%23%23branch01';
const optimizeUrl = `${startServerUrl}api/optimize/admin/testDB/local/branch/%23%23branch01`;
/*
* the dbURL dosen't change
*/
expect(connectionConfig.optimizeBranchUrl('##branch01')).to.equal(optimizeUrl);
});

it('check remove the branch', () => {
const queryUrlBranch01 = 'http://localhost:6363/api/woql/admin/testDB/local/branch/main';
// const queryFrameBranch01 = 'http://localhost:6363/api/frame/admin/testDB/local/branch/main'
const queryTriplesBranch01 = 'http://localhost:6363/api/triples/admin/testDB/local/branch/main/instance/main';
const queryUrlBranch01 = `${startServerUrl}api/woql/admin/testDB/local/branch/main`;
// const queryFrameBranch01 = `${startServerUrl}api/frame/admin/testDB/local/branch/main`
const queryTriplesBranch01 = `${startServerUrl}api/triples/admin/testDB/local/branch/main/instance/main`;
/*
*remove the ref commit it come to the
*/
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('connectionConfig tests', () => {
it('check baseUrlEncode', function() {
const db = "%6277&ˆˆˆ@ˆˆWˆTWTET#Y@&&GHHSHHS"
connectionConfig.setDB(db)
const dbBase = 'http://localhost:6363/api/woql/123/%256277%26%CB%86%CB%86%CB%86@%CB%86%CB%86W%CB%86TWTET%23Y@%26%26GHHSHHS'
const dbBase = `${startServerUrl}api/woql/123/%256277%26%CB%86%CB%86%CB%86@%CB%86%CB%86W%CB%86TWTET%23Y@%26%26GHHSHHS`;
expect(connectionConfig.dbBase('woql')).to.equal(dbBase)
expect(connectionConfig.db()).to.equal(db)

Expand All @@ -296,7 +296,7 @@ describe('connectionConfig tests', () => {

//serverUrlEncoding

//const startServerUrl = 'http://localhost:6363/'
//const startServerUrl = 'http://127.0.0.1:6363/'
//const startDBid = 'testDB'
//const organization = 'admin'

Expand Down
2 changes: 1 addition & 1 deletion test/createDatabase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('create new db tests', () => {
.stub(axiosInstance, 'post')
.returns(Promise.resolve({ status: 200, data: { 'system:status': 'system:success' } }));

expect(global.client.connectionConfig.serverURL()).to.equal('http://localhost:6363/');
expect(global.client.connectionConfig.serverURL()).to.equal('http://127.0.0.1:6363/');
global.client
.createDatabase(dbid, doc, organizationid)
.then((response) => {
Expand Down
6 changes: 3 additions & 3 deletions test/getSchema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { expect } = require('chai');
const turtleSchemaR = require('./extraFile/getSchemaTurtleResponse');
const axiosInstance = require('../lib/axiosInstance');

// http://localhost:6363/triples/terminus/schema/main
// http://localhost:6363/triples/admin/testDB/local/commit/gfhfjkflfgorpyuiioo
// http://127.0.0.1:6363/triples/terminus/schema/main
// http://127.0.0.1:6363/triples/admin/testDB/local/commit/gfhfjkflfgorpyuiioo

describe('get a terminusDB schema', () => {
const dbID = 'second_database';
Expand All @@ -14,7 +14,7 @@ describe('get a terminusDB schema', () => {
expect(global.client.connectionConfig.server).to.equal(global.url);

// console.log(JSON.stringify(global.client.connectionConfig.triplesURL('schema'), null, 4));
const schemaURL = 'http://localhost:6363/api/triples/organization01/second_database/local/branch/main/schema/main';
const schemaURL = 'http://127.0.0.1:6363/api/triples/organization01/second_database/local/branch/main/schema/main';

expect(global.client.connectionConfig.triplesURL('schema')).to.equal(schemaURL);
});
Expand Down
2 changes: 1 addition & 1 deletion test/helper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const CONNECT_RESPONSE = require('./serverResponse/connectResponseForCapabilitie

before((done) => {
console.log('before all test');
global.url = 'http://localhost:6363/';
global.url = 'http://127.0.0.1:6363/';
const key = 'root';
global.sandbox = sinon.createSandbox();
global.sandbox
Expand Down
2 changes: 1 addition & 1 deletion test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');
const UTILS = require('../lib/utils.js');

describe('utils tests', () => {
const servURL = 'http://localhost:6363/';
const servURL = 'http://127.0.0.1:6363/';

it('check standard urls', () => {
expect(UTILS.standard_urls.rdf).to.equal(UTILS.getStdURL('rdf', ''));
Expand Down
21 changes: 13 additions & 8 deletions test/woql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,20 @@ describe('woql queries', () => {
});

it('check the from method', () => {
const WOQLQuery = WOQL.limit(10);

const woqlObjectChain = WOQL.from('http://dburl').limit(10);
const woqlObject = WOQL.from('http://dburl', WOQLQuery);
const woqlObjectChain = WOQL.from('instance/main').limit(10).and();
const jsonObj = {
'@type': 'From',
graph: 'http://dburl',
graph: {
"@type": "xsd:string",
"@value": "instance/main",
},
query: {
'@type': 'Limit',
limit: 10,
query: {},
},
};

// expect(woqlObject.json()).to.eql(jsonObj);
// expect(woqlObjectChain.json()).to.eql(jsonObj);
expect(woqlObjectChain.json()).to.eql(jsonObj);
});

it('check the star method', () => {
Expand Down Expand Up @@ -496,4 +494,11 @@ describe('woql queries', () => {
expect(wq).to.deep.eql(
{"@type":"And","and":[{"@type":"Eval","expression":{"@type":"Times","left":{"@type":"ArithmeticValue","data":{"@type":"xsd:decimal","@value":3}},"right":{"@type":"ArithmeticValue","data":{"@type":"xsd:decimal","@value":4}}},"result":{"@type":"ArithmeticValue","variable":"a"}},{"@type":"Eval","expression":{"@type":"Times","left":{"@type":"ArithmeticValue","variable":"a"},"right":{"@type":"ArithmeticValue","data":{"@type":"xsd:decimal","@value":3}}},"result":{"@type":"ArithmeticValue","variable":"res"}}]})
});

it('check limit().eval()', () => {
let v = Vars("result");
const woqlObject = WOQL.limit(100).eval(WOQL.times(2, 3), v.result);
const expectedJson = {"@type":"Limit","limit":100,"query":{"@type":"Eval","expression":{"@type":"Times","left":{"@type":"ArithmeticValue","data":{"@type":"xsd:decimal","@value":2}},"right":{"@type":"ArithmeticValue","data":{"@type":"xsd:decimal","@value":3}}},"result":{"@type":"ArithmeticValue","variable":"result"}}};
expect(woqlObject.json()).to.deep.eql(expectedJson);
});
});