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

chore(tests): add auto types gen and override for testing #613

Merged
merged 4 commits into from
Apr 4, 2025

Conversation

avallete
Copy link
Member

@avallete avallete commented Mar 29, 2025

What kind of change does this PR introduce?

This PR improve the testing flow to make it more e2e by:

  1. Automatically regenerating the types definition for the test database from the latest postgres-meta version
  2. Using the "type override" for Json fields that we want to test the override on. Like recommended in the documentation. Giving an environment closer to what an user project will look like.

This will allow us to more easily go from a "sql definition" to an "type inference test".

"db:clean": "cd test/db && docker compose down --volumes",
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000"
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000",
"db:generate-test-types": "cd test/db && docker compose up --detach && wait-for-localhost 8080 && curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ../types.generated.ts && sed -i 's/export type Json = .*/export type Json = unknown;/' ../types.generated.ts"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note

Here we replace the Json type definition by unkown as it allow MergeDeep to work better to override the column type with a custom definition.

Long term, we will deprecate our custom type in favor of unknown for all Json types including for the select-query-parser. This might be a breaking change in the types system for some users.

Related: supabase/postgres-meta#750

Comment on lines +7 to +8
// TODO: should change this type in favor of unknown instead of the current one
import type { Json } from '../../src/select-query-parser/types'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note

Since select-query-parser has it's own static Json type for json field selectors, we must use this one for type equality comparator.

@avallete avallete requested a review from soedirgo March 29, 2025 15:24
@avallete avallete merged commit e1d9501 into master Apr 4, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants