If reading slangroom-chain from file we end can end up with a string like:
{
"steps": [
{
"id": "first",
"zencode": "Given nothing\nWhen I write the string 'hello' in 'say hi'\nThen print 'say_hi'",
"onAfter": (result, zencode) => {
const r = JSON.parse(result);
r['say_hi'] = 'hello from onAfter';
result = JSON.stringify(r);
return;
}
},
{
"id": "second",
"dataFromStep": "first",
"zencode": "Given I have a 'string' named 'say_hi'\nThen print the data"
}
]
}
and using JSON.parse() on it, it will obviously brake with error:
SyntaxError: Unexpected token '(', ..."onAfter": (result, z"... is not valid JSON
It could be usefull to have an utility called like chainParse that parse the JSON using an eval on the functions, but checking that the functions take only in input the required input and nothing more. To be thougth carefully since eval can expose to security risks.
I suggest that we can use yaml for chains, so you can have newlines and contracts more readable when inside the chain. Plus you can have the onAfter not breaking inside a yaml escaped string field
If reading slangroom-chain from file we end can end up with a string like:
and using JSON.parse() on it, it will obviously brake with error:
It could be usefull to have an utility called like
chainParse
that parse the JSON using aneval
on the functions, but checking that the functions take only in input the required input and nothing more. To be thougth carefully sinceeval
can expose to security risks.