From 4214ef4fb2b2239961a4d080d3a2ad64afbe2fb3 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Sun, 4 Dec 2022 23:46:30 +0100 Subject: [PATCH] nodenext compatibility --- index.d.ts | 93 ++++++++++++++++++++++++++++-------------------------- index.js | 2 ++ 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/index.d.ts b/index.d.ts index d6ea691..8efa159 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,49 +1,9 @@ import { FastifyPluginCallback } from 'fastify'; import * as Pg from 'pg'; -declare function transact( - fn: (client: Pg.PoolClient) => Promise -): Promise; - -declare function transact( - fn: (client: Pg.PoolClient) => Promise, - cb: (error: Error | null, result?: TResult) => void -): void; - -type PostgresDb = { - pool: Pg.Pool; - Client: Pg.Client; - query: Pg.Pool['query']; - connect: Pg.Pool['connect']; - transact: typeof transact; -}; - -type FastifyPostgresRouteOptions = { - transact: boolean | string; -}; - -type PostgresPluginOptions = { - /** - * Custom pg - */ - pg?: typeof Pg; - - /** - * Use pg-native - */ - native?: boolean; - - /** - * Instance name of fastify-postgres - */ - name?: string; -} & Pg.PoolConfig; - -declare const fastifyPostgres: FastifyPluginCallback; - declare module 'fastify' { export interface FastifyInstance { - pg: PostgresDb & Record; + pg: fastifyPostgres.PostgresDb & Record; } export interface FastifyRequest { @@ -51,9 +11,54 @@ declare module 'fastify' { } export interface RouteShorthandOptions { - pg?: FastifyPostgresRouteOptions; + pg?: fastifyPostgres.FastifyPostgresRouteOptions; } } -export { fastifyPostgres, PostgresDb, PostgresPluginOptions }; -export default fastifyPostgres; +type FastifyPostgres = FastifyPluginCallback; + +declare namespace fastifyPostgres { + export type PostgresDb = { + pool: Pg.Pool; + Client: Pg.Client; + query: Pg.Pool['query']; + connect: Pg.Pool['connect']; + transact: typeof transact; + }; + + export type FastifyPostgresRouteOptions = { + transact: boolean | string; + }; + + export type PostgresPluginOptions = { + /** + * Custom pg + */ + pg?: typeof Pg; + + /** + * Use pg-native + */ + native?: boolean; + + /** + * Instance name of fastify-postgres + */ + name?: string; + } & Pg.PoolConfig; + + export function transact( + fn: (client: Pg.PoolClient) => Promise + ): Promise; + + export function transact( + fn: (client: Pg.PoolClient) => Promise, + cb: (error: Error | null, result?: TResult) => void + ): void; + + export const fastifyPostgres: FastifyPostgres + export { fastifyPostgres as default } +} + +declare function fastifyPostgres(...params: Parameters): ReturnType +export = fastifyPostgres \ No newline at end of file diff --git a/index.js b/index.js index 638a20a..8add88a 100644 --- a/index.js +++ b/index.js @@ -192,3 +192,5 @@ module.exports = fp(fastifyPostgres, { fastify: '4.x', name: '@fastify/postgres' }) +module.exports.default = fastifyPostgres +module.exports.fastifyPostgres = fastifyPostgres