Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility chainParse #7

Open
matteo-cristino opened this issue Jun 6, 2024 · 1 comment
Open

Add utility chainParse #7

matteo-cristino opened this issue Jun 6, 2024 · 1 comment

Comments

@matteo-cristino
Copy link
Collaborator

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.

@puria
Copy link
Member

puria commented Jun 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants