surrealdb-client-generator icon indicating copy to clipboard operation
surrealdb-client-generator copied to clipboard

Add Support for Numeric Enums in Zod Schema Generation

Open jascenc1 opened this issue 6 months ago • 1 comments

The surql-gen tool currently lacks support for generating Zod schemas that enforce a field's value to be within a specific set of numbers (numeric enums). This is essential for cases where a SurrealDB field is restricted to specific numeric values.

Problem Example:

SurrealDB Definition:

DEFINE FIELD myNumberField ON TABLE myTable TYPE int 
ASSERT $value IN [1, 2, 3, 4, 5];

Expected Zod Schema:

const myTableInputSchema = z.object({
  myNumberField: z.union([
    z.literal(1),
    z.literal(2),
    z.literal(3),
    z.literal(4),
    z.literal(5)
  ])
});

It would be amazing if there was support for generating numeric enums in Zod schemas when the SurrealDB schema defines a field with an IN or INSIDE clause that specifies a set of numbers.

jascenc1 avatar Aug 20 '24 23:08 jascenc1