Skip to content

Commit 360d4aa

Browse files
committed
chore(tests): add types generation and database override
1 parent 88e5f30 commit 360d4aa

12 files changed

+22
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"test:types:watch": "run-s build && tsd --files 'test/**/*.test-d.ts' --watch",
4545
"db:clean": "cd test/db && docker compose down --volumes",
4646
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000",
47-
"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"
47+
"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"
4848
},
4949
"dependencies": {
5050
"@supabase/node-fetch": "^2.6.14"

test/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PostgrestClient } from '../src/index'
2-
import { CustomUserDataType, Database } from './types'
2+
import { CustomUserDataType, Database } from './types.override'
33

44
const REST_URL = 'http://localhost:3000'
55
const postgrest = new PostgrestClient<Database>(REST_URL)

test/filters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
2+
import { Database } from './types.override'
33

44
const postgrest = new PostgrestClient<Database>('http://localhost:3000')
55

test/index.test-d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { TypeEqual } from 'ts-expect'
22
import { expectError, expectType } from 'tsd'
33
import { PostgrestClient, PostgrestError } from '../src/index'
44
import { Prettify } from '../src/types'
5-
import { Database, Json } from './types'
5+
import { Json } from './types.generated'
6+
import { Database } from './types.override'
67

78
const REST_URL = 'http://localhost:3000'
89
const postgrest = new PostgrestClient<Database>(REST_URL)
@@ -191,7 +192,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
191192
}
192193
// getting this w/o the cast, not sure why:
193194
// Parameter type Json is declared too wide for argument type Json
194-
expectType<Json>(result.data.bar)
195+
expectType<typeof result.data.bar extends Json ? true : false>(true)
195196
expectType<string>(result.data.baz)
196197
}
197198

test/override-types.test-d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expectType } from 'tsd'
22
import { TypeEqual } from 'ts-expect'
33
import { PostgrestClient } from '../src'
4-
import { CustomUserDataType, Database, Json } from './types'
4+
import { CustomUserDataType, Database } from './types.override'
5+
import { Json } from './types.generated'
56

67
const REST_URL = 'http://localhost:54321'
78
const postgrest = new PostgrestClient<Database>(REST_URL)

test/resource-embedding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
2+
import { Database } from './types.override'
33

44
const postgrest = new PostgrestClient<Database>('http://localhost:3000')
55

test/select-query-parser/result.test-d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Database, Json } from '../types.override'
1+
import { Database } from '../types.override'
22
import { selectParams } from '../relationships'
33
import { GetResult } from '../../src/select-query-parser/result'
44
import { expectType } from 'tsd'
55
import { TypeEqual } from 'ts-expect'
66
import { SelectQueryError } from '../../src/select-query-parser/utils'
7+
// TODO: should change this type in favor of unknown instead of the current one
8+
import type { Json } from '../../src/select-query-parser/types'
79

810
type SelectQueryFromTableResult<
911
TableName extends keyof Database['public']['Tables'],

test/select-query-parser/rpc.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { postgrest, selectParams, RPC_NAME } from '../rpc'
2-
import { Database } from '../types'
2+
import { Database } from '../types.override'
33
import { expectType } from 'tsd'
44
import { TypeEqual } from 'ts-expect'
55

test/select-query-parser/select.test-d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,6 @@ type Schema = Database['public']
622622
username: string
623623
}
624624
}
625-
//@ts-expect-error this should work once we use unknown instead of Json type definition
626625
expectType<TypeEqual<typeof result, typeof expected>>(true)
627626
}
628627

test/transforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
2+
import { Database } from './types.override'
33

44
import { AbortController } from 'node-abort-controller'
55

0 commit comments

Comments
 (0)