Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,17 +719,14 @@ export type Database = {
const type = typesById.get(type_id)
let tsType = 'unknown'
if (type) {
tsType = `${generateNullableUnionTsType(
pgTypeToTsType(schema, type.name, {
types,
schemas,
tables,
views,
}),
true
)}`
tsType = pgTypeToTsType(schema, type.name, {
types,
schemas,
tables,
views,
})
}
return `${JSON.stringify(name)}: ${tsType}`
return `${JSON.stringify(name)}: ${tsType} | null`
})}
}`
)
Expand Down
8 changes: 7 additions & 1 deletion test/db/00-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,10 @@ LANGUAGE SQL
STABLE
AS $$
SELECT interval_test_row.duration_required * 2;
$$;
$$;

CREATE DOMAIN one_to_ten AS int CHECK (VALUE >= 1 AND VALUE <= 10);
CREATE TYPE composite_type_with_domain_attribute AS (
name text,
score one_to_ten
);
16 changes: 16 additions & 0 deletions test/server/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@
composite_type_with_array_attribute: {
my_text_array: string[] | null
}
composite_type_with_domain_attribute: {
name: string | null
score: unknown | null
}
composite_type_with_record_attribute: {
todo: Database["public"]["Tables"]["todos"]["Row"] | null
}
Expand Down Expand Up @@ -2285,6 +2289,10 @@
composite_type_with_array_attribute: {
my_text_array: string[] | null
}
composite_type_with_domain_attribute: {
name: string | null
score: unknown | null
}
composite_type_with_record_attribute: {
todo: Database["public"]["Tables"]["todos"]["Row"] | null
}
Expand Down Expand Up @@ -3510,6 +3518,10 @@
composite_type_with_array_attribute: {
my_text_array: string[] | null
}
composite_type_with_domain_attribute: {
name: string | null
score: unknown | null
}
composite_type_with_record_attribute: {
todo: Database["public"]["Tables"]["todos"]["Row"] | null
}
Expand Down Expand Up @@ -4740,6 +4752,10 @@
composite_type_with_array_attribute: {
my_text_array: string[] | null
}
composite_type_with_domain_attribute: {
name: string | null
score: unknown | null
}
composite_type_with_record_attribute: {
todo: Database["public"]["Tables"]["todos"]["Row"] | null
}
Expand Down Expand Up @@ -5265,7 +5281,7 @@

test('typegen: go', async () => {
const { body } = await app.inject({ method: 'GET', path: '/generators/go' })
expect(body).toMatchInlineSnapshot(`

Check failure on line 5284 in test/server/typegen.ts

View workflow job for this annotation

GitHub Actions / Test

test/index.test.ts > typegen: go

Error: Snapshot `typegen: go 1` mismatched - Expected + Received @@ -286,6 +286,11 @@ MyTextArray interface{} `json:"my_text_array"` } type PublicCompositeTypeWithRecordAttribute struct { Todo interface{} `json:"todo"` + } + + type PublicCompositeTypeWithDomainAttribute struct { + Name string `json:"name"` + Score interface{} `json:"score"` }" ❯ test/server/typegen.ts:5284:16
"package database

type PublicUsersSelect struct {
Expand Down Expand Up @@ -5562,7 +5578,7 @@

test('typegen: swift', async () => {
const { body } = await app.inject({ method: 'GET', path: '/generators/swift' })
expect(body).toMatchInlineSnapshot(`

Check failure on line 5581 in test/server/typegen.ts

View workflow job for this annotation

GitHub Actions / Test

test/index.test.ts > typegen: swift

Error: Snapshot `typegen: swift 1` mismatched - Expected + Received @@ -510,10 +510,18 @@ internal let MyTextArray: AnyJSON internal enum CodingKeys: String, CodingKey { case MyTextArray = "my_text_array" } } + internal struct CompositeTypeWithDomainAttribute: Codable, Hashable, Sendable { + internal let Name: String + internal let Score: OneToTenSelect + internal enum CodingKeys: String, CodingKey { + case Name = "name" + case Score = "score" + } + } internal struct CompositeTypeWithRecordAttribute: Codable, Hashable, Sendable { internal let Todo: TodosSelect internal enum CodingKeys: String, CodingKey { case Todo = "todo" } ❯ test/server/typegen.ts:5581:16
"import Foundation
import Supabase

Expand Down Expand Up @@ -6093,7 +6109,7 @@
path: '/generators/swift',
query: { access_control: 'public' },
})
expect(body).toMatchInlineSnapshot(`

Check failure on line 6112 in test/server/typegen.ts

View workflow job for this annotation

GitHub Actions / Test

test/index.test.ts > typegen: swift w/ public access control

Error: Snapshot `typegen: swift w/ public access control 1` mismatched - Expected + Received @@ -510,10 +510,18 @@ public let MyTextArray: AnyJSON public enum CodingKeys: String, CodingKey { case MyTextArray = "my_text_array" } } + public struct CompositeTypeWithDomainAttribute: Codable, Hashable, Sendable { + public let Name: String + public let Score: OneToTenSelect + public enum CodingKeys: String, CodingKey { + case Name = "name" + case Score = "score" + } + } public struct CompositeTypeWithRecordAttribute: Codable, Hashable, Sendable { public let Todo: TodosSelect public enum CodingKeys: String, CodingKey { case Todo = "todo" } ❯ test/server/typegen.ts:6112:16
"import Foundation
import Supabase

Expand Down Expand Up @@ -6624,7 +6640,7 @@
path: '/generators/python',
query: { access_control: 'public' },
})
expect(body).toMatchInlineSnapshot(`

Check failure on line 6643 in test/server/typegen.ts

View workflow job for this annotation

GitHub Actions / Test

test/index.test.ts > typegen: python

Error: Snapshot `typegen: python 1` mismatched - Expected + Received @@ -258,6 +258,10 @@ class PublicCompositeTypeWithArrayAttribute(BaseModel): my_text_array: List[str] = Field(alias="my_text_array") class PublicCompositeTypeWithRecordAttribute(BaseModel): - todo: PublicTodos = Field(alias="todo")" + todo: PublicTodos = Field(alias="todo") + + class PublicCompositeTypeWithDomainAttribute(BaseModel): + name: str = Field(alias="name") + score: PublicOneToTen = Field(alias="score")" ❯ test/server/typegen.ts:6643:16
"from __future__ import annotations

import datetime
Expand Down
Loading