Skip to content

Add utility chainParse #7

@matteo-cristino

Description

@matteo-cristino

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions