supabase/postgres-meta

Generate concrete typescript types for JSON columns based on pg_jsonschema

Opened this issue · 0 comments

When I create JSON checks on columns with pg_jsonschema it would be super cool to have it also in generated ts types.

Currently when I create the following table

CREATE TABLE public.some_table (
    id SERIAL PRIMARY KEY,
    arr jsonb not null check (
      jsonb_matches_schema ('{
        "type": "array",
        "items": {
           "type": "string"
         }       
      }',
      arr
      )
    )
);

Generating types with supabase gen types typescript produces the following types

...
arr: JSON
...

But I'd like to get

...
arr: string[]
...

Potentially it would be achievable by parsing passed schema in checks via a tool like https://github.com/bcherny/json-schema-to-typescript

Describe alternatives you've considered
I haven't found any other alternatives aligned with the current CLI architecture

Additional context
I don't know what I'd expect with more complex check expressions. Maybe ignore them and fall back to JSON.