From da0e77787a5c5a079861a7a1c8aeb9eb81bdfda8 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Wed, 17 Aug 2022 11:48:16 +0200 Subject: [PATCH 1/7] use reusable workflow (#143) * use reusable workflow * use correct reusable workflow * remove test:ci npm script * use lint --- .github/workflows/ci.yml | 83 ++-------------------------------------- package.json | 5 ++- 2 files changed, 7 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a44caa..7a05045 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,83 +11,8 @@ on: - '*.md' jobs: - dependency-review: - name: Dependency Review - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Check out repo - uses: actions/checkout@v3 - with: - persist-credentials: false - - - name: Dependency review - uses: actions/dependency-review-action@v2 - test: - runs-on: ubuntu-latest - permissions: - contents: read - strategy: - matrix: - node-version: [14, 16, 18] - services: - postgres: - image: postgres:11-alpine - env: - POSTGRES_USER: postgres - POSTGRES_DB: postgres - POSTGRES_PASSWORD: postgres - ports: - - '5432:5432' - options: >- - --health-cmd pg_isready --health-interval 10s --health-timeout 5s - --health-retries 5 - steps: - - name: Check out repo - uses: actions/checkout@v3 - with: - persist-credentials: false - - - name: Setup Node ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: Install dependencies - run: npm i - - - name: CI environment setup - run: > - npm i node-gyp - - sudo apt-get install -yqq libpq-dev postgresql-client - - chmod 600 .pgpass - - PGPASSFILE=.pgpass psql -h localhost -p ${{ - job.services.postgres.ports[5432] }} -d postgres -c 'CREATE TABLE - users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U - postgres - - - name: Run tests - run: | - npm run test:ci - - automerge: - name: Automerge Dependabot PRs - if: > - github.event_name == 'pull_request' && - github.event.pull_request.user.login == 'dependabot[bot]' - needs: test - permissions: - pull-requests: write - contents: write - runs-on: ubuntu-latest - steps: - - uses: fastify/github-action-merge-dependabot@v3 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - target: major + uses: fastify/workflows/.github/workflows/plugins-ci-postgres.yml@v3 + with: + license-check: true + lint: true diff --git a/package.json b/package.json index 5a87f09..57732ab 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,12 @@ "types": "index.d.ts", "scripts": { "check-examples": "tsc --build examples/typescript/*", + "lint": "standard", "lint:fix": "standard --fix", "load-data": "docker exec -it fastify-postgres psql -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres -d postgres", "postgres": "docker run -p 5432:5432 --name fastify-postgres -e POSTGRES_PASSWORD=postgres -d postgres:11-alpine", - "test": "standard && tap -J test/*.test.js && npm run test:typescript", - "test:ci": "standard && tap -J test/*.test.js --coverage-report=lcovonly && npm run test:typescript", + "test": "npm run test:unit && npm run test:typescript", + "test:unit": "tap -J test/*.test.js", "test:report": "standard && tap -J --coverage-report=html test/*.test.js", "test:typescript": "tsd", "test:verbose": "standard && tap -J test/*.test.js -Rspec" From 487806af9316ddfe0f34d7c712ece006c22284dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Aug 2022 06:56:45 +0000 Subject: [PATCH 2/7] build(deps-dev): bump tsd from 0.22.0 to 0.23.0 (#144) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.22.0 to 0.23.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.22.0...v0.23.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 57732ab..2633eeb 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "pg-native": "^3.0.0", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.22.0", + "tsd": "^0.23.0", "typescript": "^4.4.3" }, "peerDependencies": { From 75d08f5d17c6e24255dbc746e2cf74e0703cd74d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 04:06:44 +0000 Subject: [PATCH 3/7] build(deps-dev): bump tsd from 0.23.0 to 0.24.1 (#145) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.23.0 to 0.24.1. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.23.0...v0.24.1) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2633eeb..8e18a80 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "pg-native": "^3.0.0", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.23.0", + "tsd": "^0.24.1", "typescript": "^4.4.3" }, "peerDependencies": { From 0fe8ea9ec6a2f6a8a84062f50810e00c379df63e Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Mon, 5 Dec 2022 00:29:15 +0100 Subject: [PATCH 4/7] disable package-lock generation (#147) --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From c5f3aa819bfca0593473a3a60f4aa9ba9492c9a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Dec 2022 04:03:01 +0000 Subject: [PATCH 5/7] build(deps-dev): bump tsd from 0.24.1 to 0.25.0 (#149) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.24.1 to 0.25.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.24.1...v0.25.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8e18a80..0a490a3 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "pg-native": "^3.0.0", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.24.1", + "tsd": "^0.25.0", "typescript": "^4.4.3" }, "peerDependencies": { From 06986a293937b3737a5f251e33249e34354005c7 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Mon, 5 Dec 2022 08:15:39 +0100 Subject: [PATCH 6/7] nodenext compatibility (#148) --- 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 From 62a39e223df634ae5dbe9a556b562a77575e0802 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 5 Dec 2022 10:37:43 +0100 Subject: [PATCH 7/7] Bumped v5.2.0 Signed-off-by: Matteo Collina --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a490a3..52af880 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fastify/postgres", - "version": "5.1.0", + "version": "5.2.0", "description": "Fastify PostgreSQL connection plugin", "main": "index.js", "types": "index.d.ts",