surrealdb / surrealdb

A scalable, distributed, collaborative, document-graph database, for the realtime web
https://surrealdb.com
Other
26.53k stars 839 forks source link

Bug: Arguments lost when passing to a scripting function #4331

Open LucyEgan opened 1 month ago

LucyEgan commented 1 month ago

Describe the bug

The types point and bytes as lost when passing to a scripting function.

Steps to reproduce

LET $t = {
    array: [
        1,
        "g"
    ],
    bool: true,
    bytes: <bytes>"do i byte, or do a nibble? naa i just bit",
    datetime: <datetime>"2022-06-07T00:00:00Z",
    duration: 30s,
    number: 4,
    object: {
        t: 5,
        subObj: {
            cake: 'yay'
        }
    },
    point: <point>[1, 2],
    record: cake:please,
    string: '',
    uuid: <uuid> "a8f30d8b-db67-47ec-8b38-ef703e05ad1b",
    none: NONE,
};
(function($t){
    return {
        surrealArgs: arguments,
        jsonArgs: JSON.stringify(arguments, (key, value)=>{if(value === undefined)return 'I WAS UNDEFINED 😭'; return value;}, 4),
    }
});

The above will produce the following

{
    jsonArgs: '{
    "0": {
        "array": [
            1,
            "g"
        ],
        "bool": true,
        "bytes": "I WAS UNDEFINED 😭",
        "datetime": "2022-06-07T00:00:00.000Z",
        "duration": "30s",
        "none": "I WAS UNDEFINED 😭",
        "number": 4,
        "object": {
            "subObj": {
                "cake": "yay"
            },
            "t": 5
        },
        "point": "I WAS UNDEFINED 😭",
        "record": "cake:please",
        "string": "",
        "uuid": "a8f30d8b-db67-47ec-8b38-ef703e05ad1b"
    }
}',
    surrealArgs: {
        0: {
            array: [
                1,
                'g'
            ],
            bool: true,
            bytes: NONE,
            datetime: '2022-06-07T00:00:00Z',
            duration: 30s,
            none: NONE,
            number: 4,
            object: {
                subObj: {
                    cake: 'yay'
                },
                t: 5
            },
            point: NONE,
            record: cake:please,
            string: '',
            uuid: 'a8f30d8b-db67-47ec-8b38-ef703e05ad1b'
        }
    }
}

Expected behaviour

The returned surrealArgs should be the same as what went in, along with the equivalent javascript/json conversions

surrealArgs: {
    0: {
        array: [
            1,
            'g'
        ],
        bool: true,
        bytes: "do i byte, or do a nibble? naa i just bit", <<<< as bytes
        datetime: '2022-06-07T00:00:00Z',
        duration: 30s,
        none: NONE,
        number: 4,
        object: {
            subObj: {
                cake: 'yay'
            },
            t: 5
        },
        point: (1, 2), <<<< should as a surreal point
        record: cake:please,
        string: '',
        uuid: 'a8f30d8b-db67-47ec-8b38-ef703e05ad1b'
    }
}

SurrealDB version

2.0.0-alpha.4 for linux on x86_64

Contact Details

lucy.e@aspirecomps.co.uk

Is there an existing issue for this?

Code of Conduct

gguillemas commented 1 month ago

Thank you for reporting this issue @LucyEgan! This seems related to the new parser, maybe @DelSkayn can take a look when he has some time.

vignesh-j-shetty commented 3 weeks ago

This issue is at rquickjs not at parser level @gguillemas

gguillemas commented 3 weeks ago

Thank you @vignesh-j-shetty! That makes sense, of course. In any case, @DelSkayn is also the author of rquickjs so he should be the right person to look into this either way :+1: