Closed Vratislav closed 2 years ago
@Vratislav I don't think this is a Superface issue, from the map it seems that nothing is done with the body.data
, did you look at the response if it's a problem there? if not, could you try Array.isArray on activities
? arrays actually are objects in javascript..
I do not know, where exactly the problem is, but the behaviour is unexpected.
If I receive body.data
and data is an array (confirmed by postman) and then I do activities = body.data.map((d) => ...)
on it, the result is a Map with IDs as a keys. :-/
Huh, that's strange. I can replicate with doing this in the map:
activities = [1,2,3].map(d => d)
Output is:
{ '0': 1, '1': 2, '2': 3 }
Maybe linked to: https://github.com/patriksimek/vm2/issues/198
The minimalistic replication is
deals = [1,2,3]
Output is:
{ '0': 1, '1': 2, '2': 3 }
I am just thinking whether JSON.stringify and then JSON.parse on the result after the sandbox boundary would be a good workaround or not.
Can you please specify your node --version
?
I managed to reproduce [ 1, 2, 3, '0': 1, '1': 2, '2': 3 ]
on v10.23.0
but jest still claims toStrictEqual([1, 2, 3])
and Array.isArray
also returns true.
On node v12.19.1
, v14.15.1
and v15.2.0
I cannot reproduce this.
My node is v12.4.0. I will try to update to the latest LTS
I am still replicating this with:
ts-node v4.1.0
node v14.15.1
typescript v2.9.2
But i can only replicate it as part of map walkthrough. If I do a test on the sandbox itself, such as:
it('passes array unchanged', () => {
expect(evalScript('[1,2,3]')).toStrictEqual([1, 2, 3]);
});
I cannot replicate it either
Cannot it be the
async visitAssignmentNode(node: AssignmentNode): Promise<NonPrimitive> {
return this.constructObject(node.key, await this.visit(node.value));
}
in the map-interpreter.ts ?
It seems to me that everything it touches, it objectifies.
I've created a branch and a PR where I added the debug
package and logging calls to some interesting places in map-interpreter
and Sandbox
here https://github.com/superfaceai/superface/pull/18.
You can see the debug output by setting environment variable DEBUG='superface:*'
before executing the code.
I also added a test which should test your theory with constructObject
but sadly that doesn't seem to be it.
I am still replicating this with:
ts-node v4.1.0 node v14.15.1 typescript v2.9.2
It looks like your ts-node
and typescript
versions are pretty old. Can you try upgrading those as well? If it's a dependency version bug it'd be great if we could find where it starts.
i still can't reproduce, try the version upgrade (superface needs typescript > 4, i'm surprised it works at all). it definitely seems linked to the vm though
Fixed by #27
This issue seems to be reintroduced in vm2: https://github.com/patriksimek/vm2/issues/198
Behavior
given profile snippet
and given map snippet
result.value.activities
contains Dictionary instead of Array (Array indicies are used as keys)Expected behaviour
I expected
result.value.activities
to contain array(But maybe I am wrong and the map implicitly dictates conversion to Dictionary in this case?)