Skip to content

Add Support for Numeric Enums in Zod Schema Generation #55

@jascenc1

Description

@jascenc1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions