Skip to content

Commit 207e9c5

Browse files
oliverbutlermichaelangriveramichaelangeloio
authored
feat: add nest 9 and 10 to @ts-rest/nest (#325)
* feat: add nest 9 and 10 to @ts-rest/nest * feat: upgrade NX and Nest to latest * fix: DI issue with Reflector so instantiated a new instance * fix: remove rxjs as a main dependency to fix TS issues during nest migration * chore: fix lock files for new deps * refactor: update build-test-all command * chore: add new default @vitest/coverage-v8 dep * add changeset boilerplate * Update flat-rivers-build.md * feat: fix lock --------- Co-authored-by: michaelangrivera <mar@michaelangrivera.com> Co-authored-by: Michael Angelo Rivera <55844504+michaelangelo-io@users.noreply.github.com>
1 parent a7755ef commit 207e9c5

14 files changed

Lines changed: 4162 additions & 2020 deletions

File tree

.changeset/flat-rivers-build.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@ts-rest/nest': minor
3+
---
4+
5+
We now support the following versions of Nestjs:
6+
```
7+
"@nestjs/common": "^9.0.0 || ^10.0.0",
8+
"@nestjs/core": "^9.0.0 || ^10.0.0",
9+
```

apps/example-express/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
},
3131
"serve": {
32-
"executor": "@nx/node:node",
32+
"executor": "@nx/js:node",
3333
"options": {
3434
"buildTarget": "example-express:build"
3535
},

apps/example-microservice/posts-service/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
},
3232
"serve": {
33-
"executor": "@nx/node:node",
33+
"executor": "@nx/js:node",
3434
"options": {
3535
"buildTarget": "example-microservice-posts-service:build"
3636
},

apps/example-microservice/users-service/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
},
3232
"serve": {
33-
"executor": "@nx/node:node",
33+
"executor": "@nx/js:node",
3434
"options": {
3535
"buildTarget": "example-microservice-users-service:build"
3636
},

apps/example-microservice/users-service/tsconfig.app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"module": "commonjs",
66
"types": ["node"],
77
"emitDecoratorMetadata": true,
8-
"target": "es2015"
8+
"target": "es2021"
99
},
1010
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
1111
"include": ["**/*.ts"]

apps/example-nest/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
},
3232
"serve": {
33-
"executor": "@nx/node:node",
33+
"executor": "@nx/js:node",
3434
"options": {
3535
"buildTarget": "example-nest:build"
3636
},

apps/example-nest/tsconfig.app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"module": "commonjs",
66
"types": ["node"],
77
"emitDecoratorMetadata": true,
8-
"target": "es2015",
8+
"target": "es2021",
99
"strict": true,
1010
"strictNullChecks": true
1111
},

apps/example-next/project.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"targets": {
77
"build": {
88
"executor": "@nx/next:build",
9-
"outputs": ["{options.outputPath}"],
9+
"outputs": [
10+
"{options.outputPath}"
11+
],
1012
"defaultConfiguration": "production",
1113
"options": {
12-
"root": "apps/example-next",
1314
"outputPath": "dist/apps/example-next"
1415
},
1516
"configurations": {
@@ -45,18 +46,27 @@
4546
},
4647
"test": {
4748
"executor": "@nx/jest:jest",
48-
"outputs": ["{workspaceRoot}/coverage/apps/example-next"],
49+
"outputs": [
50+
"{workspaceRoot}/coverage/apps/example-next"
51+
],
4952
"options": {
5053
"jestConfig": "apps/example-next/jest.config.ts",
5154
"passWithNoTests": true,
52-
"coverageReporters": ["lcov", "text-summary"]
55+
"coverageReporters": [
56+
"lcov",
57+
"text-summary"
58+
]
5359
}
5460
},
5561
"lint": {
5662
"executor": "@nx/linter:eslint",
57-
"outputs": ["{options.outputFile}"],
63+
"outputs": [
64+
"{options.outputFile}"
65+
],
5866
"options": {
59-
"lintFilePatterns": ["apps/example-next/**/*.{ts,tsx,js,jsx}"]
67+
"lintFilePatterns": [
68+
"apps/example-next/**/*.{ts,tsx,js,jsx}"
69+
]
6070
}
6171
}
6272
},

libs/ts-rest/nest/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"directory": "libs/ts-rest/nest"
2121
},
2222
"peerDependencies": {
23-
"@nestjs/common": "^9.0.0",
24-
"@nestjs/core": "^9.0.0",
23+
"@nestjs/common": "^9.0.0 || ^10.0.0",
24+
"@nestjs/core": "^9.0.0 || ^10.0.0",
2525
"rxjs": "^7.1.0",
2626
"zod": "^3.21.0"
2727
},
@@ -31,9 +31,9 @@
3131
}
3232
},
3333
"devDependencies": {
34-
"@nestjs/platform-express": "^9.4.3",
35-
"@nestjs/platform-fastify": "^9.4.3",
36-
"fastify": "^4.17.0"
34+
"@nestjs/platform-express": "^9.0.0 || ^10.0.0",
35+
"@nestjs/platform-fastify": "^9.0.0 || ^10.0.0",
36+
"fastify": "^4.0.0"
3737
},
3838
"typedoc": {
3939
"entryPoint": "./src/index.ts",

libs/ts-rest/nest/src/lib/ts-rest-nest-handler.spec.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Body,
1111
Controller,
1212
Get,
13-
INestApplication,
1413
Post,
1514
UploadedFile,
1615
UseInterceptors,
@@ -20,10 +19,7 @@ import * as supertest from 'supertest';
2019
import { TsRest } from './ts-rest.decorator';
2120
import path = require('path');
2221
import { FileInterceptor } from '@nestjs/platform-express';
23-
import {
24-
FastifyAdapter,
25-
NestFastifyApplication,
26-
} from '@nestjs/platform-fastify';
22+
import { FastifyAdapter } from '@nestjs/platform-fastify';
2723

2824
export type Equal<a, b> = (<T>() => T extends a ? 1 : 2) extends <
2925
T
@@ -56,12 +52,6 @@ describe('doesUrlMatchContractPath', () => {
5652
});
5753

5854
describe('ts-rest-nest-handler', () => {
59-
let app: INestApplication;
60-
61-
afterEach(async () => {
62-
await app.close();
63-
});
64-
6555
describe('multi-handler api', () => {
6656
it('should be able to implement a whole contract', async () => {
6757
const c = initContract();
@@ -111,7 +101,7 @@ describe('ts-rest-nest-handler', () => {
111101
controllers: [TestController],
112102
}).compile();
113103

114-
app = moduleRef.createNestApplication();
104+
const app = moduleRef.createNestApplication();
115105
await app.init();
116106

117107
const responseGet = await supertest(app.getHttpServer())
@@ -164,7 +154,7 @@ describe('ts-rest-nest-handler', () => {
164154
controllers: [SingleHandlerTestController],
165155
}).compile();
166156

167-
app = moduleRef.createNestApplication();
157+
const app = moduleRef.createNestApplication();
168158
await app.init();
169159

170160
const response = await supertest(app.getHttpServer())
@@ -250,7 +240,7 @@ describe('ts-rest-nest-handler', () => {
250240
controllers: [SingleHandlerTestController],
251241
}).compile();
252242

253-
app = moduleRef.createNestApplication();
243+
const app = moduleRef.createNestApplication();
254244
await app.init();
255245

256246
const response = await supertest(app.getHttpServer()).get('/test').send();
@@ -299,7 +289,7 @@ describe('ts-rest-nest-handler', () => {
299289
controllers: [SingleHandlerTestController],
300290
}).compile();
301291

302-
app = moduleRef.createNestApplication();
292+
const app = moduleRef.createNestApplication();
303293
await app.init();
304294

305295
const response = await supertest(app.getHttpServer())
@@ -366,7 +356,7 @@ describe('ts-rest-nest-handler', () => {
366356
controllers: [SingleHandlerTestController],
367357
}).compile();
368358

369-
app = moduleRef.createNestApplication();
359+
const app = moduleRef.createNestApplication();
370360
await app.init();
371361

372362
const response = await supertest(app.getHttpServer()).get('/test').send();
@@ -428,7 +418,7 @@ describe('ts-rest-nest-handler', () => {
428418
controllers: [SingleHandlerTestController],
429419
}).compile();
430420

431-
app = moduleRef.createNestApplication();
421+
const app = moduleRef.createNestApplication();
432422
await app.init();
433423

434424
const responseNested = await supertest(app.getHttpServer())
@@ -557,7 +547,7 @@ describe('ts-rest-nest-handler', () => {
557547
controllers: [SingleHandlerTestController],
558548
}).compile();
559549

560-
app = moduleRef.createNestApplication();
550+
const app = moduleRef.createNestApplication();
561551
await app.init();
562552

563553
const response = await supertest(app.getHttpServer())
@@ -618,7 +608,7 @@ describe('ts-rest-nest-handler', () => {
618608
controllers: [SingleHandlerTestController],
619609
}).compile();
620610

621-
app = moduleRef.createNestApplication();
611+
const app = moduleRef.createNestApplication();
622612
await app.init();
623613

624614
const response = await supertest(app.getHttpServer()).get('/test').send();
@@ -668,7 +658,7 @@ describe('ts-rest-nest-handler', () => {
668658
controllers: [SingleHandlerTestController],
669659
}).compile();
670660

671-
app = moduleRef.createNestApplication();
661+
const app = moduleRef.createNestApplication();
672662
await app.init();
673663

674664
const response = await supertest(app.getHttpServer()).get('/test').send();
@@ -736,7 +726,7 @@ describe('ts-rest-nest-handler', () => {
736726
controllers: [SingleHandlerTestController],
737727
}).compile();
738728

739-
app = moduleRef.createNestApplication();
729+
const app = moduleRef.createNestApplication();
740730
await app.init();
741731

742732
const response = await supertest(app.getHttpServer())
@@ -848,7 +838,7 @@ describe('ts-rest-nest-handler', () => {
848838
controllers: [MultiTypeHandlerController],
849839
}).compile();
850840

851-
app = moduleRef.createNestApplication();
841+
const app = moduleRef.createNestApplication();
852842

853843
await app.init();
854844

@@ -983,9 +973,7 @@ describe('ts-rest-nest-handler', () => {
983973
controllers: [FastifyController],
984974
}).compile();
985975

986-
app = moduleRef.createNestApplication<NestFastifyApplication>(
987-
new FastifyAdapter()
988-
);
976+
const app = moduleRef.createNestApplication(new FastifyAdapter());
989977

990978
await app.init();
991979
await app.getHttpAdapter().getInstance().ready();

0 commit comments

Comments
 (0)