Parser

class
 new Parser() 

Option name Type Description

Handles logic related to results sent back to the console
These can be custom crafted to suit different server outputs.
Either because of a custom serializer or if a call is made to a server side script.
It also allows for a change in the way the elements are displayed in html and how the history entries are generated

class Parser {
Option name Type Description
_rawResults;
Option name Type Description
_rawError;

constructor

constructor
 constructor() 

Option name Type Description
err Error

A potential error from the database.

results Mixed

The server results for a query

return Void

Constructor takes a server response and holds onto it until it is required.
You can create this object without passing any params. Do this if you need to hold onto it before populating it or to create multiple Parsers.

constructor(err, results) {
        this._rawError = err;
        this._rawResults = results;
}

create

method
 create() 

Option name Type Description
err Error

A potential error from the database.

results Mixed

The server results for a query

return Parser

A populated Parser object

Creates a Parser object

create(err, results) {
    return new Parser(err, results);
}

getRawResults

method
 getRawResults() 

Option name Type Description
return Mixed

raw server results

Get the raw result data

getRawResults() {
    return this._rawResults;
}

getRawError

method
 getRawError() 

Option name Type Description
return Mixed

raw error

Get the raw error info

getRawError() {
    return this._rawError;
}

getResults

method
 getResults() 

Option name Type Description
return Mixed

raw server results

Get generic results.
These results are constructed in a way the console can comprehend them.
Extend this if you're receiving non conventional data from the server

getResults() {
    return this.getRawResults();
}

getError

method
 getError() 

Option name Type Description
return Mixed

raw error

Get the raw error info
These results are constructed in a way the console can comprehend them.
Extend this if you're receiving non conventional data from the server

getError() {
    return this.getRawError();
}

getHtmlResults

method
 getHtmlResults() 

Option name Type Description
return String, DOM

the element you want to append to the console window

get the HTML results to put into the window dom element
Extend this for custom behavior

getHtmlResults() {
    var jsonResultSet = '';
    this.getResults().forEach( (entry) => {
        jsonResultSet += Html.jsonSyntaxHighlight(entry) + '<br/>';
    });
    return $('<div>').addClass("port-response json").html(jsonResultSet);
}

getHtmlError

method
 getHtmlError() 

Option name Type Description
return String, DOM

the element you want to append to the console window

get the HTML error to put into the window dom element
Extend this for custom behavior

getHtmlError() {
    return $('<div>').addClass("port-error").html('Could not complete query => ' + Html.htmlEncode(this.getError().message))
}

getHistory

method
 getHistory() 

Option name Type Description
return Object

the "line" in a history entry.

Return a line of the history entry for this result.
This is usefull if you want to customize the history entry. However remember that:
{error:"na", query:""} are required

getHistory() {
    return {results: this.getRawResults(), error: this.getError()};
}
}

export default Parser;