cli icon indicating copy to clipboard operation
cli copied to clipboard

Generate const array of possible enum values

Open gwax opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I would like to have values matching possible enum values that are synchronized to the database schema for looping or use with zod and similar tools.

Describe the solution you'd like A clear and concise description of what you want to happen.

for a schema:

export type Database = {
  public: {
    Enums: {
      mytype: "value" | "other"
    }
  }
}

I would like to have generated values:

export const DatabaseValues = {
  public: {
    Enums: {
      mytype: ["value", "other"],
    },
  },
} as const;

this would allow defining zod types to match like:

const mySchema = z.object({
  mytype: z.enum(DatabaseValues.public.Enums.mytype),
});

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

  • manually keeping values in sync with the database and hoping they don't fall out of sync
  • writing custom type checkers to ensure that values match the schema

Additional context Add any other context or screenshots about the feature request here.

gwax avatar Aug 09 '24 19:08 gwax