@@ -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 */
357372WOQLClient . 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 */
414429WOQLClient . 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 */
435450WOQLClient . prototype . dispatchFetch = function ( url , action , payload ) {
436451 const api = {
0 commit comments