Skip to content

Commit

Permalink
v10.0.0 (#2282)
Browse files Browse the repository at this point in the history
* feat: health indicator for Prisma ORM (#2250)

* chore: drop support for Node v12

BREAKING CHANGE: drop support for Node v12

* chore: fix prisma sample

* chore: add prisma client as optional peer dependency

* refactor(prisma): rename PrismaORM to PrismaHealthIndicator

* chore(): release v10.0.0-beta.0

* chore: fix format

* chore: add node v18 and v20

* chore: drop support for node v14

BREAKING CHANGE:
drop support for node v14

* feat: upgrade to nest v10

* feat(deps): upgrade TypeScript to v5

* chore: update dependencies

* feat(disk): prettify type information

* chore(): release v10.0.0-beta.1

* Revert "feat(disk): prettify type information"

This reverts commit e0b13aa.

* chore: use --legacy-peer-deps in ci

Revert once mikro-orm/nestjs#122 is resolved

* chore: remove prisma timeout

* chore: add debian openssl for prisma

---------

Co-authored-by: Thalles Passos <[email protected]>
  • Loading branch information
BrunnerLivio and ThallesP authored Jun 16, 2023
1 parent 6ecdc1f commit 291bbed
Show file tree
Hide file tree
Showing 42 changed files with 11,520 additions and 7,253 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tests/**
lib/**/*.spec.ts
lib/**/*.spec.ts
e2e/prisma/generated/**
5 changes: 3 additions & 2 deletions .github/workflows/build-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -36,7 +36,8 @@ jobs:
continue-on-error: true
run: npm list

- run: npm ci
# TODO: Remove --legacy-peer-deps once https://github.com/mikro-orm/nestjs/issues/122 is resolved
- run: npm ci --legacy-peer-deps
- run: npm run build:all
env:
CI: true
5 changes: 3 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -37,5 +37,6 @@ jobs:
continue-on-error: true
run: npm list

- run: npm ci
# TODO: Remove --legacy-peer-deps once https://github.com/mikro-orm/nestjs/issues/122 is resolved
- run: npm ci --legacy-peer-deps
- run: npm run test:e2e
7 changes: 4 additions & 3 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Use Node.js 14.x
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- name: Cache node modules
id: cache-npm
Expand All @@ -32,5 +32,6 @@ jobs:
continue-on-error: true
run: npm list

- run: npm ci
# TODO: Remove --legacy-peer-deps once https://github.com/mikro-orm/nestjs/issues/122 is resolved
- run: npm ci --legacy-peer-deps
- run: npm run format:check
7 changes: 4 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Use Node.js 14.x
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- name: Cache node modules
id: cache-npm
Expand All @@ -32,5 +32,6 @@ jobs:
continue-on-error: true
run: npm list

- run: npm ci
# TODO: Remove --legacy-peer-deps once https://github.com/mikro-orm/nestjs/issues/122 is resolved
- run: npm ci --legacy-peer-deps
- run: npm run lint
5 changes: 3 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -36,7 +36,8 @@ jobs:
continue-on-error: true
run: npm list

- run: npm ci
# TODO: Remove --legacy-peer-deps once https://github.com/mikro-orm/nestjs/issues/122 is resolved
- run: npm ci --legacy-peer-deps
- run: npm run build
- run: npm test
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ npm-debug.log
/test
/coverage
/.nyc_output
e2e/prisma/generated

# dist
dist
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e2e/prisma/generated/
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@


# [10.0.0-beta.1](https://github.com/nestjs/terminus/compare/9.2.2...10.0.0-beta.1) (2023-06-16)


### Bug Fixes

* **deps:** update dependency @grpc/grpc-js to v1.8.14 ([#2262](https://github.com/nestjs/terminus/issues/2262)) ([86152cc](https://github.com/nestjs/terminus/commit/86152cc617d07e3ed902c52c8557247ce0957a77))
* **deps:** update dependency @grpc/grpc-js to v1.8.15 ([#2280](https://github.com/nestjs/terminus/issues/2280)) ([6ecdc1f](https://github.com/nestjs/terminus/commit/6ecdc1f243948f62375d9e0da812fcd85e676e8d))
* **deps:** update dependency @grpc/proto-loader to v0.7.6 ([#2263](https://github.com/nestjs/terminus/issues/2263)) ([638a7cd](https://github.com/nestjs/terminus/commit/638a7cd04ffc504640c00bba1390dca1c659cf2c))
* **deps:** update dependency @grpc/proto-loader to v0.7.7 ([#2268](https://github.com/nestjs/terminus/issues/2268)) ([48d2d8d](https://github.com/nestjs/terminus/commit/48d2d8d168145b47032a67a7456f8636f1f71d40))
* **deps:** update dependency @mikro-orm/nestjs to v5.1.8 ([#2265](https://github.com/nestjs/terminus/issues/2265)) ([4bdb17d](https://github.com/nestjs/terminus/commit/4bdb17d9ab2c151cfe4a91dbc1500d78fb4f9656))
* **deps:** update dependency @nestjs/mongoose to v9.2.2 ([#2267](https://github.com/nestjs/terminus/issues/2267)) ([d97deb7](https://github.com/nestjs/terminus/commit/d97deb762f5ec1035b8366dda64763d92de6562b))
* **deps:** update dependency @nestjs/sequelize to v9.0.2 ([#2269](https://github.com/nestjs/terminus/issues/2269)) ([3de1168](https://github.com/nestjs/terminus/commit/3de11681f4520b8a17498877fb80bdde02256a99))
* **deps:** update dependency ioredis to v5.3.2 ([#2281](https://github.com/nestjs/terminus/issues/2281)) ([3b58611](https://github.com/nestjs/terminus/commit/3b58611d7b1a088b7f76d19f5c4ac6b8ddf3b45c))
* **deps:** update dependency mysql2 to v3.2.4 ([#2216](https://github.com/nestjs/terminus/issues/2216)) ([38c9593](https://github.com/nestjs/terminus/commit/38c95939a46cc73face8e2d3f780658068629395))


### chore

* drop support for Node v12 ([260d170](https://github.com/nestjs/terminus/commit/260d170cb9c45386d7e79e367177297d874d4cc0))
* drop support for node v14 ([5f15d10](https://github.com/nestjs/terminus/commit/5f15d10bbb1559eb151c32c8153b46121bdbbfba))


### Features

* **deps:** upgrade TypeScript to v5 ([1e9d40e](https://github.com/nestjs/terminus/commit/1e9d40e301f9ab1943c69527cff88af23bc7ddaf))
* **disk:** prettify type information ([e0b13aa](https://github.com/nestjs/terminus/commit/e0b13aac8069bb510c508783171aad2a87444fb1))
* health indicator for Prisma ORM ([#2250](https://github.com/nestjs/terminus/issues/2250)) ([6960af6](https://github.com/nestjs/terminus/commit/6960af6eb4780af92a4f2097527df69d6c745bdb))
* upgrade to nest v10 ([b1e4aa2](https://github.com/nestjs/terminus/commit/b1e4aa23134a793428f5f286f46865916d8c6e7a))


### BREAKING CHANGES

* drop support for node v14
* drop support for Node v12

# [10.0.0-beta.0](https://github.com/nestjs/terminus/compare/9.2.2...10.0.0-beta.0) (2023-04-25)


### chore

* drop support for Node v12 ([beee03c](https://github.com/nestjs/terminus/commit/beee03cd9d01f8b936c3cdc2e61406ef1755dd8f))


### Features

* health indicator for Prisma ORM ([#2250](https://github.com/nestjs/terminus/issues/2250)) ([bef105d](https://github.com/nestjs/terminus/commit/bef105d7fb1ccf4be373e854fb918cc5a446687f))


### BREAKING CHANGES

* drop support for Node v12

## [9.2.2](https://github.com/nestjs/terminus/compare/9.2.1...9.2.2) (2023-03-27)


Expand Down
128 changes: 128 additions & 0 deletions e2e/health-checks/prisma.health.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { INestApplication } from '@nestjs/common';
import { PrismaClient as MongoPrismaClient } from '../prisma/generated/mongodb';
import { PrismaClient as MySQLPrismaClient } from '../prisma/generated/mysql';
import { bootstrapTestingModule, DynamicHealthEndpointFn } from '../helper';
import * as request from 'supertest';

jest.setTimeout(300_000);

describe('PrismaHealthIndicator', () => {
let app: INestApplication;
let setHealthEndpoint: DynamicHealthEndpointFn;

describe('mongodb', () => {
beforeEach(
() =>
(setHealthEndpoint = bootstrapTestingModule()
.withPrisma()
.andMongo().setHealthEndpoint),
);

describe('#pingCheck', () => {
it('should check if the prisma is available', async () => {
app = await setHealthEndpoint(({ healthCheck, prisma }) =>
healthCheck.check([
async () =>
prisma.pingCheck('prismamongo', new MongoPrismaClient()),
]),
).start();

return request(app.getHttpServer())
.get('/health')
.expect(200)
.expect({
status: 'ok',
info: { prismamongo: { status: 'up' } },
error: {},
details: { prismamongo: { status: 'up' } },
});
});

it('should throw an error if runs into timeout error', async () => {
app = await setHealthEndpoint(({ healthCheck, prisma }) =>
healthCheck.check([
async () =>
prisma.pingCheck('prismamongo', new MongoPrismaClient(), {
timeout: 1,
}),
]),
).start();

return request(app.getHttpServer())
.get('/health')
.expect(503)
.expect({
status: 'error',
info: {},
error: {
prismamongo: {
status: 'down',
message: 'timeout of 1ms exceeded',
},
},
details: {
prismamongo: {
status: 'down',
message: 'timeout of 1ms exceeded',
},
},
});
});
});
});

describe('mysql', () => {
beforeEach(
() =>
(setHealthEndpoint = bootstrapTestingModule()
.withPrisma()
.andMySql().setHealthEndpoint),
);

describe('#pingCheck', () => {
it('should check if the prisma is available', async () => {
app = await setHealthEndpoint(({ healthCheck, prisma }) =>
healthCheck.check([
async () => prisma.pingCheck('prisma', new MySQLPrismaClient()),
]),
).start();

return request(app.getHttpServer())
.get('/health')
.expect({
status: 'ok',
info: { prisma: { status: 'up' } },
error: {},
details: { prisma: { status: 'up' } },
});
});

it('should throw an error if runs into timeout error', async () => {
app = await setHealthEndpoint(({ healthCheck, prisma }) =>
healthCheck.check([
async () =>
prisma.pingCheck('prisma', new MySQLPrismaClient(), {
timeout: 1,
}),
]),
).start();

return request(app.getHttpServer())
.get('/health')
.expect(503)
.expect({
status: 'error',
error: {
prisma: { status: 'down', message: 'timeout of 1ms exceeded' },
},
info: {},
details: {
prisma: { status: 'down', message: 'timeout of 1ms exceeded' },
},
});
});
});
});

afterEach(async () => await app.close());
});
16 changes: 16 additions & 0 deletions e2e/helper/bootstrap-testing-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
MemoryHealthIndicator,
MicroserviceHealthIndicator,
MongooseHealthIndicator,
PrismaHealthIndicator,
SequelizeHealthIndicator,
TerminusModule,
TypeOrmHealthIndicator,
Expand All @@ -37,6 +38,7 @@ type TestingHealthFunc = (props: {
sequelize: SequelizeHealthIndicator;
typeorm: TypeOrmHealthIndicator;
mikroOrm: MikroOrmHealthIndicator;
prisma: PrismaHealthIndicator;
}) => Promise<HealthCheckResult>;

function createHealthController(func: TestingHealthFunc) {
Expand All @@ -52,6 +54,7 @@ function createHealthController(func: TestingHealthFunc) {
private readonly sequelize: SequelizeHealthIndicator,
private readonly typeorm: TypeOrmHealthIndicator,
private readonly mikroOrm: MikroOrmHealthIndicator,
private readonly prisma: PrismaHealthIndicator,
) {}
@Get('health')
health() {
Expand All @@ -65,6 +68,7 @@ function createHealthController(func: TestingHealthFunc) {
sequelize: this.sequelize,
typeorm: this.typeorm,
mikroOrm: this.mikroOrm,
prisma: this.prisma,
});
}
}
Expand Down Expand Up @@ -178,6 +182,17 @@ export function bootstrapTestingModule() {
};
}

function withPrisma() {
return {
andMySql: () => {
return { setHealthEndpoint };
},
andMongo: () => {
return { setHealthEndpoint };
},
};
}

function withHttp() {
imports.push(HttpModule);
return { setHealthEndpoint };
Expand All @@ -188,6 +203,7 @@ export function bootstrapTestingModule() {
withTypeOrm,
withSequelize,
withHttp,
withPrisma,
withMikroOrm,
setHealthEndpoint,
};
Expand Down
11 changes: 11 additions & 0 deletions e2e/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module '*prisma/generated/mongodb' {
class PrismaClient {
$runCommandRaw(command: unknown): any;
}
}

declare module '*prisma/generated/mysql' {
class PrismaClient {
$queryRawUnsafe(query: string): any;
}
}
1 change: 1 addition & 0 deletions e2e/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"setupFiles": ["<rootDir>/jest.setup.ts"],
"testRegex": "/e2e/.*\\.(e2e-test|e2e-spec).(ts|tsx|js)$",
"collectCoverageFrom": [
"src/**/*.{js,jsx,tsx,ts}",
Expand Down
4 changes: 4 additions & 0 deletions e2e/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { execSync } from 'child_process';

execSync(`npx [email protected] generate --schema e2e/prisma/schema-mysql.prisma`);
execSync(`npx [email protected] generate --schema e2e/prisma/schema-mongodb.prisma`);
Loading

0 comments on commit 291bbed

Please sign in to comment.