Skip to content

Conversation

avallete
Copy link
Member

What kind of change does this PR introduce?

  • Follow up refactor isolating duplicated typescript generation logic into their own dedicated functions

@avallete avallete requested review from a team as code owners September 24, 2025 09:59
@avallete avallete requested a review from soedirgo September 24, 2025 09:59
Comment on lines 620 to 633
export const Constants = {
${schemas
.sort(({ name: a }, { name: b }) => a.localeCompare(b))
.map((schema) => {
const schemaEnums = types
.filter((type) => type.schema === schema.name && type.enums.length > 0)
.sort(({ name: a }, { name: b }) => a.localeCompare(b))
return `${JSON.stringify(schema.name)}: {
${schemas.map((schema) => {
const schemaEnums = introspectionBySchema[schema.name].enums
return `${JSON.stringify(schema.name)}: {
Enums: {
${schemaEnums.map(
(enum_) =>
`${JSON.stringify(enum_.name)}: [${enum_.enums
.map((variant) => JSON.stringify(variant))
.join(', ')}]`
)}
}
}`
})}
})}
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

Forgot to remove this loop, now we can use the introspectionSchema directly where the values are already filtered and sorted.

Comment on lines -234 to -240
${relationships
.filter(
(relationship) =>
relationship.schema === table.schema &&
relationship.referenced_schema === table.schema &&
relationship.relation === table.name
)
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

Noticed that I forgot this loop, instead I now push those into the introspectedSchema object under each table/view so we don't have to filter and sort everytime.

Also extracted the typegen into it's own dedicated function reducing duplication across tables/views definitions.

Base automatically changed from chore/refactor-typegen-loops to master September 29, 2025 18:45
Comment on lines +172 to +174
const getFunctionTsReturnType = (fn: PostgresFunction, returnType: string) => {
return `${returnType}${fn.is_set_returning_function ? '[]' : ''}`
}
Copy link
Member

Choose a reason for hiding this comment

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

Only used in one place, I think we can inline this

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, those two will be growing a lot in the next PR though which is why I've did the split here. So in the next PR we can focus over the changes scoped to those functions: https://github.com/supabase/postgres-meta/pull/971/files#diff-c903ec71df16a8ae5f665c19c21b273f74c2f8eb02f5e8a3552ebe69d18be18fR214-R265

Copy link
Member

Choose a reason for hiding this comment

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

Ack, thx for the rationale 👍

return 'unknown'
}

const getFunctionSignatures = (
Copy link
Member

Choose a reason for hiding this comment

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

Also only used in one place

Copy link
Member Author

Choose a reason for hiding this comment

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

@avallete avallete merged commit 09155b0 into master Oct 1, 2025
6 checks passed
@avallete avallete deleted the chore/isolate-function-type-generation branch October 1, 2025 08:18
@coveralls
Copy link

Pull Request Test Coverage Report for Build 18155869351

Details

  • 228 of 233 (97.85%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 82.354%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/server/templates/typescript.ts 228 233 97.85%
Totals Coverage Status
Change from base Build 18107275683: -0.05%
Covered Lines: 5726
Relevant Lines: 6812

💛 - Coveralls

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.

3 participants