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

Allow insertion of custom types for 'Json' type with the 'gen types typescript' command #590

Closed
codewriter73 opened this issue Nov 9, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@codewriter73
Copy link

codewriter73 commented Nov 9, 2022

Feature request

After having to manually change the JSON values of my types file every time I generate a new ones, it gets repetitive. It seems like it should possible to have those types replace automatically when the supabase gen types typescript is run.

Describe the solution you'd like

I'm not exactly sure how this would be approached, but it seems one possible solution would be to pass in a file path to a json file that mimics the organization of the generated types file, such as
{
[schemaName]: {
.. "Tables": {
.... [tableName]: {
....... [rowname]: string | number | boolean | null | {
............. ...typeJsonStructure
.......... } | {
............. ...typeJsonStructure
.......... }[]
...... }
.. },
.. "Views": {},
.. "Functions": {},
}

An example file would be like
{ public: { Tables: { user: { myJsonColumn: { customParamOne: string customParamTwo: number } } }, Views: { userView: { viewJsonColumn: { viewColOne: string: viewColTwo: { nestedOne: boolean; nestedTwo: number | string' } } } } }

Describe alternatives you've considered

I have not seen anything related to JSON specifically, but @magick93 suggested support for Custom PostgreSQL types in this issue supabase/postgres-meta#840

@codewriter73 codewriter73 added the enhancement New feature or request label Nov 9, 2022
@soedirgo
Copy link
Member

Hey @codewriter73, we've updated the docs to include the recommended way to merge/replace types. With this, you write the generated types to one file (e.g. database-generated.ts) and write the replacements in another file that imports the former (e.g. database.ts), so that way you don't have to keep manually replacing the types.

@codewriter73
Copy link
Author

@soedirgo Thanks for pointing that out! I'll have to look into it more. I ended up writing my own script that uses typescript's compiler API to compare the generated DatabaseTypes.ts and my own AugmentTypes.ts to replace the types and output to a clean types file. I messed around with using abstract types to merge the two but I found it made it difficult to use typescript's language feature when trying to get a quick glance at the return types, etc

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

3 participants