Skip to content

Commit e1d9501

Browse files
authored
Merge pull request #613 from supabase/chore/add-auto-types-gen-and-override-for-testing
chore(tests): add auto types gen and override for testing
2 parents 956ed18 + 7d8be6d commit e1d9501

16 files changed

+339
-220
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
4040
"test": "run-s format:check test:types db:clean db:run test:run db:clean && node test/smoke.cjs && node test/smoke.mjs",
4141
"test:run": "jest --runInBand --coverage",
42-
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean",
42+
"test:update": "run-s db:clean db:run db:generate-test-types && jest --runInBand --updateSnapshot && run-s db:clean",
4343
"test:types": "run-s build && tsd --files 'test/**/*.test-d.ts'",
44+
"test:types:watch": "run-s build && tsd --files 'test/**/*.test-d.ts' --watch",
4445
"db:clean": "cd test/db && docker compose down --volumes",
45-
"db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000"
46+
"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 && sed -i 's/export type Json = .*/export type Json = unknown;/' ../types.generated.ts"
4648
},
4749
"dependencies": {
4850
"@supabase/node-fetch": "^2.6.14"

test/basic.ts

+1-1
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/db/docker-compose.yml

+6
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ services:
2828
POSTGRES_PASSWORD: postgres
2929
POSTGRES_HOST: /var/run/postgresql
3030
POSTGRES_PORT: 5432
31+
pgmeta:
32+
image: supabase/postgres-meta:v0.87.1
33+
ports:
34+
- '8080:8080'
35+
environment:
36+
- PG_META_DB_URL=postgresql://postgres:postgres@db:5432/postgres

test/filters.ts

+1-1
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

+2-3
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 '../src/select-query-parser/types'
6+
import { Database } from './types.override'
67

78
const REST_URL = 'http://localhost:3000'
89
const postgrest = new PostgrestClient<Database>(REST_URL)
@@ -189,8 +190,6 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
189190
if (result.error) {
190191
throw new Error(result.error.message)
191192
}
192-
// getting this w/o the cast, not sure why:
193-
// Parameter type Json is declared too wide for argument type Json
194193
expectType<Json>(result.data.bar)
195194
expectType<string>(result.data.baz)
196195
}

test/override-types.test-d.ts

+2-1
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/relationships.ts

+1-1
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 REST_URL = 'http://localhost:3000'
55
export const postgrest = new PostgrestClient<Database>(REST_URL)

test/resource-embedding.ts

+1-1
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/returns.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expectType } from 'tsd'
22
import { PostgrestBuilder, PostgrestClient } from '../src/index'
3-
import { Database } from './types'
3+
import { Database } from './types.override'
44
import { TypeEqual } from 'ts-expect'
55

66
const REST_URL = 'http://localhost:3000'

test/rpc.ts

+1-1
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 REST_URL = 'http://localhost:3000'
55
export const postgrest = new PostgrestClient<Database>(REST_URL)

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Database, Json } from '../types'
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

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TypeEqual } from 'ts-expect'
33
import { Json } from '../../src/select-query-parser/types'
44
import { SelectQueryError } from '../../src/select-query-parser/utils'
55
import { Prettify } from '../../src/types'
6-
import { CustomUserDataType, Database } from '../types'
6+
import { CustomUserDataType, Database } from '../types.override'
77
import { selectQueries } from '../relationships'
88

99
// This test file is here to ensure that for a query against a specfic datatabase

test/transforms.ts

+1-1
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)