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

Lines changed: 4 additions & 2 deletions
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

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

Lines changed: 6 additions & 0 deletions
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

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: 2 additions & 3 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 '../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

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/relationships.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 REST_URL = 'http://localhost:3000'
55
export 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/returns.test-d.ts

Lines changed: 1 addition & 1 deletion
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

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

0 commit comments

Comments
 (0)