Skip to content

SDK string conversion issues #50

@hammo92

Description

@hammo92

The JS SDK adds the s parameter to all parameters provided as a string; this prevents Surreal from inferring types and forces a difference between the input and output schemas for a table. This causes errors with our schema definitions as we are expecting to be able to pass a date string to date fields but this will throw an error:

await db.query(`DEFINE TABLE test SCHEMAFULL; DEFINE FIELD time ON test TYPE datetime; DEFINE FIELD relation ON test TYPE record<test>;`)

//fails
await db.create("test", {
    relation: new RecordId("test", "123"),
    time: new Date().toIsoString()
})
// successful
await db.create("test", {
    relation: new RecordId("test", "123"),
    time: new Date()
}) 

But our generated type for this table would be

 z.object({
    relation: recordId('test'),
    time: z.string().datetime()
})

Barring a change to the SDK I think the best approach is likely to create a custom Zod type for dates similar to the recordId type which applies a transform and converts the value to a date; this would allow us to provide a string or date object argument for datetime fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions