Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "c8 --100 node --test",
"test:report": "standard && c8 --reporter html node --test",
"test:typescript": "tsd"
"test:typescript": "tstyche"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -74,16 +74,13 @@
"neostandard": "^0.13.0",
"pg": "^8.11.3",
"pg-native": "^3.0.1",
"tsd": "^0.33.0",
"tstyche": "^7.0.0",
"typescript": "~6.0.2"
},
"peerDependencies": {
"pg": ">=6.0.0"
},
"tsd": {
"directory": "test-types"
},
"publishConfig": {
"access": "public"
}
}
}
File renamed without changes.
Comment thread
Tony133 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fastify from 'fastify'
import * as pg from 'pg'
import { expectAssignable, expectType } from 'tsd'

import fastifyPostgres, { PostgresDb } from '../index'
import { expect } from 'tstyche'
import fastifyPostgres, { PostgresDb } from '..'

const app = fastify()

Expand Down Expand Up @@ -34,6 +33,7 @@ app.register(fastifyPostgres, {

// Plugin property available
app.after(() => {
expectAssignable<PostgresDb>(app.pg)
expectType<PostgresDb>(app.pg.users)
expect(app.pg).type.toBeAssignableTo<PostgresDb | undefined>()
expect(app.pg.users).type.toBe<PostgresDb | undefined>()
expect(app.pg.posts).type.toBe<PostgresDb | undefined>()
})
30 changes: 0 additions & 30 deletions test-types/query.test-d.ts

This file was deleted.

27 changes: 27 additions & 0 deletions test-types/query.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fastify from 'fastify'
import { type Client, type Pool, type PoolClient, type QueryResult } from 'pg'
import { expect } from 'tstyche'
import fastifyPostgres, { type PostgresDb } from '..'

const app = fastify()

app.register(fastifyPostgres, {
connectionString: 'postgres://user:password@host:port/db',
})

app.get('/calc', async () => {
expect(app.pg).type.toBeAssignableTo<PostgresDb>()

expect(app.pg.pool).type.toBe<Pool>()
expect(app.pg.Client).type.toBe<Client>()

const client = await app.pg.connect()
expect(client).type.toBe<PoolClient>()

const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum')
expect(sumResult).type.toBe<QueryResult<{ sum: number }>>()

client.release()

return { sum: sumResult.rows }
})
Comment thread
Tony133 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import fastify from 'fastify'
import { PoolClient, QueryResult } from 'pg'
import { expectType } from 'tsd'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import fastifyPostgres, { PostgresDb } from '../index'
import { expect } from 'tstyche'
import fastifyPostgres from '..'

const app = fastify()

Expand All @@ -19,12 +17,12 @@ app.post('/insert-async', async () => {
`

const transactionResult = await app.pg.transact((client) => {
expectType<PoolClient>(client)
expect(client).type.toBe<PoolClient>()

return client.query<{ sum: number }>(insertQuery)
})

expectType<QueryResult<{ sum: number }>>(transactionResult)
expect(transactionResult).type.toBe<QueryResult<{ sum: number }>>()

return transactionResult
})
Expand All @@ -38,13 +36,13 @@ app.post('/insert-cb', (_req, reply) => {

app.pg.transact(
(client) => {
expectType<PoolClient>(client)
expect(client).type.toBe<PoolClient>()

return client.query<{ sum: number }>(insertQuery)
},
(error, result) => {
expectType<Error | null>(error)
expectType<QueryResult<{ sum: number }> | undefined>(result)
expect(error).type.toBe<Error | null>()
expect(result).type.toBe<QueryResult<{ sum: number }> | undefined>()

if (error) {
reply.status(500).send(error)
Expand Down
Loading