Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Numeric Enums in Zod Schema Generation #55

Open
jascenc1 opened this issue Aug 20, 2024 · 1 comment
Open

Add Support for Numeric Enums in Zod Schema Generation #55

jascenc1 opened this issue Aug 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jascenc1
Copy link

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.

@sebastianwessel sebastianwessel added the enhancement New feature or request label Aug 20, 2024
@sebastianwessel
Copy link
Owner

Thx for your feedback.
We will try to get this into the lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants