Skip to content

Commit e6af57e

Browse files
committed
add date and datetime to woql
1 parent 98fa2c8 commit e6af57e

File tree

5 files changed

+110
-6
lines changed

5 files changed

+110
-6
lines changed

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 string date literal from the input
1274+
* @param {string} date - any date string format YYYY-MM-DD
1275+
* @returns {object} - A JSON-LD literal
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 string datetime literal from the input
1286+
* @param {string} date - any datetime string format YYYY-MM-DDThh-mm-ssZ
1287+
* @returns {object} - A JSON-LD literal
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 boolean literal from the input
1298+
* @param {boolean} bool - true | false
1299+
* @returns {object} - A JSON-LD literal
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(),

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)