This does not appear to be documented anywhere so hopefully this will clear up my questions and also act as a reference document. Here is my understanding and questions at the end.
When creating custom extensions there are 3 main ways to parse dynamic data
So, for example, if we have a a query called "query1" passed from a module via the HJSON interface from an input named "myquery" options, then options.myquery would return
"query1".
To obtain the actual data this must be parsed to get the dynamic content
1. The must basic method is simply:
this.parse(options.myquery)
This is simple enough and will parse the input "input" returning the JSON of the query named "query1" like
{ "id" : 1, "name" : "Brian"}
2. Additionally we have:
this.parseRequired(options.myquery)
ParseRequired is used like this:
const queryParsed = this.parseRequired(options,myquery, 'string', 'query parameter is required.');
This will parse the query in the same way as (1) but will throw an error if the parameters is missing/ cant be parsed.
Note there are 3 parameters, the myquery, a data type and error message. (question about this below)
3. Lastly there is parseOptional()
parseOptional() is used like this
const queryParsed =this.parseOptional('myquery', 'string', 'defaultvalue')
In this case 'query1' is parsed as above but if not successfully parsed, a default value is set in it's place.
I have actually used these methods successfully in the past but always felt i was not 100% confident in relation to some points so here it comes.
So my questions are:
- is the above a correct summary?
- Does the data type apply to the expected datatype of the incoming data to options.myquery.
- Are all data types allowed?
