Skip to content

Commit ca1dfc4

Browse files
Merge pull request #237 from terminusdb/coveralls-next
add extra types to woql
2 parents 85a0a9a + d6e3ea1 commit ca1dfc4

File tree

7 files changed

+159
-7
lines changed

7 files changed

+159
-7
lines changed

docs/api/woql.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,54 @@ literal(1, "nonNegativeInteger")
13591359
//returns { "@type": "xsd:nonNegativeInteger", "@value": 1 }
13601360
```
13611361

1362+
## date
1363+
##### WOQL.date(date) ⇒ <code>object</code>
1364+
Generates explicitly a JSON-LD literal date from the imput
1365+
1366+
**Returns**: <code>object</code> - - A JSON-LD literal date
1367+
1368+
| Param | Type | Description |
1369+
| --- | --- | --- |
1370+
| date | <code>string</code> | any date format string (YYYY-MM-DD) |
1371+
1372+
**Example**
1373+
```javascript
1374+
date("2022-10-02")
1375+
//returns { "@type": "xsd:date", "@value": "2022-10-02" }
1376+
```
1377+
1378+
## datetime
1379+
##### WOQL.datetime(datetime) ⇒ <code>object</code>
1380+
Generates explicitly a JSON-LD literal datetime from the imput
1381+
1382+
**Returns**: <code>object</code> - - A JSON-LD literal datetime
1383+
1384+
| Param | Type | Description |
1385+
| --- | --- | --- |
1386+
| datetime | <code>string</code> | any datetime format string (YYYY-MM-DDThh-mm-ssZ) |
1387+
1388+
**Example**
1389+
```javascript
1390+
datetime("2022-10-19T14:17:12Z")
1391+
//returns { "@type": "xsd:dateTime", "@value": "2022-10-19T14:17:12Z" }
1392+
```
1393+
1394+
## boolean
1395+
##### WOQL.boolean(bool) ⇒ <code>object</code>
1396+
Generates explicitly a JSON-LD literal boolean from the input
1397+
1398+
**Returns**: <code>object</code> - - A JSON-LD literal boolean
1399+
1400+
| Param | Type | Description |
1401+
| --- | --- | --- |
1402+
| bool | <code>boolean</code> | true | false |
1403+
1404+
**Example**
1405+
```javascript
1406+
boolean(true)
1407+
//returns { "@type": "xsd:boolean", "@value": true }
1408+
```
1409+
13621410
## iri
13631411
##### WOQL.iri(val) ⇒ <code>object</code>
13641412
Explicitly sets a value to be an IRI - avoiding automatic type marshalling

lib/accessControl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ AccessControl.prototype.ifOrganizationExists = function (orgName) {
472472
* })
473473
*/
474474
AccessControl.prototype.createOrganizationRemote = function (orgName) {
475-
// maybe we have to review this
476475
const payload = { organization: orgName };
477476
return this.dispatch(`${this.baseURL}/private/organizations`, CONST.POST, payload);
478477
};

lib/viewer/tableConfig.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ WOQLTableConfig.prototype.json = function () {
4949

5050
WOQLTableConfig.prototype.loadJSON = function (config, rules) {
5151
const jr = [];
52-
for (let i = 0; i < rules.length; i++) {
53-
// eslint-disable-next-line no-use-before-define
54-
const nr = new WOQLTableRule();
55-
nr.json(rules[i]);
56-
jr.push(nr);
52+
if (Array.isArray(rules)) {
53+
for (let i = 0; i < rules.length; i++) {
54+
// eslint-disable-next-line no-use-before-define
55+
const nr = new WOQLTableRule();
56+
nr.json(rules[i]);
57+
jr.push(nr);
58+
}
5759
}
5860
this.rules = jr;
61+
if (!config) return this;
5962
if (typeof config.column_order !== 'undefined') {
6063
this.column_order(...config.column_order);
6164
}

lib/woql.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,42 @@ WOQL.literal = function (val, type) {
12691269
return new WOQLQuery().literal(val, type);
12701270
};
12711271

1272+
/**
1273+
* Generates explicitly a JSON-LD literal date from the imput
1274+
* @param {string} date - any date format string (YYYY-MM-DD)
1275+
* @returns {object} - A JSON-LD literal date
1276+
* @example
1277+
* date("2022-10-02")
1278+
* //returns { "@type": "xsd:date", "@value": "2022-10-02" }
1279+
*/
1280+
WOQL.date = function (date) {
1281+
return new WOQLQuery().literal(date, 'xsd:date');
1282+
};
1283+
1284+
/**
1285+
* Generates explicitly a JSON-LD literal datetime from the imput
1286+
* @param {string} datetime - any datetime format string (YYYY-MM-DDThh-mm-ssZ)
1287+
* @returns {object} - A JSON-LD literal datetime
1288+
* @example
1289+
* datetime("2022-10-19T14:17:12Z")
1290+
* //returns { "@type": "xsd:dateTime", "@value": "2022-10-19T14:17:12Z" }
1291+
*/
1292+
WOQL.datetime = function (datetime) {
1293+
return new WOQLQuery().literal(datetime, 'xsd:dateTime');
1294+
};
1295+
1296+
/**
1297+
* Generates explicitly a JSON-LD literal boolean from the input
1298+
* @param {boolean} bool - true | false
1299+
* @returns {object} - A JSON-LD literal boolean
1300+
* @example
1301+
* boolean(true)
1302+
* //returns { "@type": "xsd:boolean", "@value": true }
1303+
*/
1304+
WOQL.boolean = function (bool) {
1305+
return new WOQLQuery().boolean(bool);
1306+
};
1307+
12721308
/**
12731309
* Explicitly sets a value to be an IRI - avoiding automatic type marshalling
12741310
* @param {string} val string which will be treated as an IRI

lib/woqlClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ WOQLClient.prototype.getVersionDiff = function (beforeVersion, afterVersion, id,
16611661
if (id) {
16621662
payload.document_id = id;
16631663
}
1664+
// console.log(this.connectionConfig.diffURL())
16641665
return this.dispatch(
16651666
CONST.POST,
16661667
this.connectionConfig.diffURL(),

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": "10.0.21",
3+
"version": "10.0.22",
44
"description": "TerminusDB client library",
55
"main": "index.js",
66
"types": "./dist/typescript/index.d.ts",

test/woql.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,69 @@ describe('woql queries', () => {
383383
})
384384
});
385385

386+
387+
it('check type_of(boolean,Var)', () => {
388+
const TypeOf = WOQL.type_of(WOQL.boolean(true), 'v:Y').json()
389+
expect(TypeOf).to.deep.eql({
390+
"@type": "TypeOf",
391+
"value": {
392+
"@type": "Value",
393+
"data": {
394+
"@type": "xsd:boolean",
395+
"@value": true
396+
}
397+
},
398+
"type": {
399+
"@type": "NodeValue",
400+
"variable": "Y"
401+
}
402+
})
403+
});
404+
405+
406+
it('check datetime', () => {
407+
const TypeOf = WOQL.triple("v:a", "datetime", WOQL.datetime("2022-10-19T21:14:20Z")).json()
408+
expect(TypeOf).to.deep.eql({
409+
"@type": "Triple",
410+
"subject": {
411+
"@type": "NodeValue",
412+
"variable": "a"
413+
},
414+
"predicate": {
415+
"@type": "NodeValue",
416+
"node": "datetime"
417+
},
418+
"object": {
419+
"@type": "Value",
420+
"data": {
421+
"@type": "xsd:dateTime",
422+
"@value": "2022-10-19T21:14:20Z"
423+
}
424+
}
425+
})
426+
});
427+
428+
429+
it('check date', () => {
430+
const TypeOf = WOQL.triple("v:a", "date", WOQL.date("2022-10-19")).json()
431+
expect(TypeOf).to.deep.eql({
432+
"@type": "Triple",
433+
"subject": {
434+
"@type": "NodeValue",
435+
"variable": "a"
436+
},
437+
"predicate": {
438+
"@type": "NodeValue",
439+
"node": "date"
440+
},
441+
"object": {
442+
"@type": "Value",
443+
"data": {
444+
"@type": "xsd:date",
445+
"@value": "2022-10-19"
446+
}
447+
}
448+
})
449+
});
450+
386451
});

0 commit comments

Comments
 (0)