Skip to content

Commit 4065639

Browse files
committed
adding end oint for logging messages
1 parent 9343291 commit 4065639

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

lib/connectionConfig.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ConnectionConfig.prototype.schemaURL = function () {
8484

8585
/**
8686
* @param {String} inputStr - the URL of a Terminus DB base install or schema endpoint
87-
* @param {Object} [context] optional json-ld context
87+
* @param {Object} [context] optional json-ld context
8888
* sets the connection to point at the query api URL
8989
*/
9090
ConnectionConfig.prototype.setQueryURL = function (inputStr, context) {
@@ -102,9 +102,11 @@ ConnectionConfig.prototype.queryURL = function () {
102102
return `${this.dbURL()}/woql`;
103103
};
104104

105+
106+
105107
/**
106108
* @param {String} inputStr - the URL of a Terminus DB base install or frame endpoint
107-
* @param {Object} [context] optional json-ld context
109+
* @param {Object} [context] optional json-ld context
108110
* sets the connection to point at the class frame api URL
109111
*/
110112
ConnectionConfig.prototype.setClassFrameURL = function (inputStr, context) {
@@ -124,7 +126,7 @@ ConnectionConfig.prototype.frameURL = function () {
124126

125127
/**
126128
* @param {String} inputStr - the URL of a Terminus DB base install or document endpoint
127-
* @param {Object} [context] optional json-ld context
129+
* @param {Object} [context] optional json-ld context
128130
* sets the connection to point at the document api URL
129131
*/
130132
ConnectionConfig.prototype.setDocument = function (inputStr, context) {

lib/const.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = Object.freeze({
1111
UPDATE_DOCUMENT: 'update_document',
1212
CLASS_FRAME: 'class_frame',
1313
WOQL_SELECT: 'woql_select',
14+
TERMINUS_MESSAGE: 'terminus_message',
1415
GET_DOCUMENT: 'get_document',
1516
DELETE_DATABASE: 'delete_database',
1617
DELETE_DOCUMENT: 'delete_document',

lib/dispatchRequest.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ErrorMessage = require('./errorMessage');
66

77

88
/**
9-
* base 64 encodes a string using either the btoa implementation if available or the Buffer object.
9+
* base 64 encodes a string using either the btoa implementation if available or the Buffer object.
1010
* @param {String} str string to be base 64 encoded
1111
*/
1212
function btoaImplementation(str) {
@@ -21,7 +21,7 @@ function btoaImplementation(str) {
2121
/**
2222
* @file Dispatch Request
2323
* @license Apache Version 2
24-
* @description Functions for dispatching API requests via the axios library.
24+
* @description Functions for dispatching API requests via the axios library.
2525
* @param {String} url API endpoint URL
2626
* @param {String} action API action
2727
* @param {Object} payload data to be transmitted to endpoint
@@ -59,6 +59,7 @@ function DispatchRequest(url, action, payload) {
5959
case CONST.UPDATE_SCHEMA:
6060
case CONST.CREATE_DOCUMENT:
6161
case CONST.UPDATE_DOCUMENT:
62+
case CONST.TERMINUS_MESSAGE:
6263
case CONST.WOQL_UPDATE:
6364
options.headers = options.headers ? options.headers : {};
6465
options.headers['Content-Type'] = 'application/json';
@@ -86,7 +87,7 @@ function DispatchRequest(url, action, payload) {
8687
if(err.response && err.response.data){
8788
e.data = err.response.data;
8889
}
89-
throw e;
90+
throw e;
9091
});
9192
}
9293
}

lib/woqlClient.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const UTILS = require('./utils.js');
1313
* Simple Javascript Client for accessing the Terminus DB API
1414
* Constructor - takes an option json list of connection parameters
1515
* @param {Object} params a json object containing connection parameters
16-
* which can be:
16+
* which can be:
1717
* params.server URL of server to connect to
1818
* params.dbid ID of database to connect to
1919
* params.docid = ID of document to load;
@@ -326,6 +326,21 @@ WOQLClient.prototype.update = function (qurl, woql, opts) {
326326
return this.dispatch(this.connectionConfig.queryURL(), CONST.WOQL_SELECT, q);
327327
};
328328

329+
/**
330+
* Executes a WOQL query on the server which keeps log of messages
331+
*
332+
* the first argument (payload) will include the message
333+
* the third argument (opts) is an options json - opts.key is an optional API key
334+
*/
335+
WOQLClient.prototype.serverLog = function (payload, opts) {
336+
let endpoint = this.connectionConfig.server + "message";
337+
let q = {'@type' : "terminus:APIUpdate", "terminus:message" : payload};
338+
339+
q = this.addOptionsToWOQL(q, opts);
340+
return this.dispatch(endpoint, CONST.TERMINUS_MESSAGE, q);
341+
};
342+
343+
329344
/**
330345
* Retrieves a WOQL query on the specified database which updates the state and returns the results
331346
*
@@ -352,7 +367,7 @@ WOQLClient.prototype.getClassFrame = function (cfurl, cls, opts) {
352367

353368
/**
354369
* Adds a key to the passed woql query if it is present in the opts json
355-
*
370+
*
356371
*/
357372
WOQLClient.prototype.addOptionsToWOQL = function (woql, opts) {
358373
if (opts && opts.key) {
@@ -369,7 +384,7 @@ WOQLClient.prototype.addOptionsToDocument = function (doc, opts) {
369384
const pdoc = {};
370385
pdoc['@context'] = doc['@context'];
371386
// add blank node prefix as document base url
372-
if (pdoc['@context'] && doc['@id']) {
387+
if (pdoc['@context'] && doc['@id']) {
373388
pdoc['@context']._ = `${doc['@id']}/`;
374389
}
375390
if (opts && opts['terminus:encoding'] && opts['terminus:encoding'] === 'terminus:turtle') {
@@ -408,7 +423,7 @@ WOQLClient.prototype.addKeyToPayload = function (payload, url) {
408423

409424
/**
410425
* Document updates include the URL in both the endpoint and the document itself
411-
* This ensures that they are the same by using the endpoint URL as the authoritative version
426+
* This ensures that they are the same by using the endpoint URL as the authoritative version
412427
* and copying it into the embedded document ID
413428
*/
414429
WOQLClient.prototype.makeDocumentConsistentWithURL = function (doc, dburl) {
@@ -430,7 +445,7 @@ WOQLClient.prototype.dispatch = function (url, action, payload) {
430445
};
431446

432447
/**
433-
* If the use_fetch switch is set, the browser's built in fetch will be used rather than the npm axios module
448+
* If the use_fetch switch is set, the browser's built in fetch will be used rather than the npm axios module
434449
*/
435450
WOQLClient.prototype.dispatchFetch = function (url, action, payload) {
436451
const api = {

0 commit comments

Comments
 (0)