A progressive Node.js framework for building efficient and scalable server-side applications.
+ + + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ pnpm install +``` + +## Running the app + +```bash +# development +$ pnpm run start + +# watch mode +$ pnpm run start:dev + +# production mode +$ pnpm run start:prod +``` + +## Test + +```bash +# unit tests +$ pnpm run test + +# e2e tests +$ pnpm run test:e2e + +# test coverage +$ pnpm run test:cov +``` + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil MyĆliwiec](https://kamilmysliwiec.com) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](LICENSE). diff --git a/references/nestjs-example/nest-cli.json b/references/nestjs-example/nest-cli.json new file mode 100644 index 0000000000..f9aa683b1a --- /dev/null +++ b/references/nestjs-example/nest-cli.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true + } +} diff --git a/references/nestjs-example/package.json b/references/nestjs-example/package.json new file mode 100644 index 0000000000..78769c86ea --- /dev/null +++ b/references/nestjs-example/package.json @@ -0,0 +1,72 @@ +{ + "name": "nestjs-example", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "scripts": { + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "test": "jest", + "test:watch": "jest --watch", + "test:cov": "jest --coverage", + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "test:e2e": "jest --config ./test/jest-e2e.json" + }, + "dependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "@nestjs/config": "^3.0.1", + "@nestjs/platform-express": "^10.0.0", + "reflect-metadata": "^0.1.13", + "@trigger.dev/sdk": "workspace:*", + "@trigger.dev/nestjs": "workspace:*", + "rxjs": "^7.8.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@nestjs/testing": "^10.0.0", + "@types/express": "^4.17.17", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.1", + "@types/supertest": "^2.0.12", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "eslint": "^8.42.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "jest": "^29.5.0", + "prettier": "^3.0.0", + "source-map-support": "^0.5.21", + "supertest": "^6.3.3", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + "typescript": "^5.1.3" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": "src", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node" + } +} diff --git a/references/nestjs-example/src/app.controller.ts b/references/nestjs-example/src/app.controller.ts new file mode 100644 index 0000000000..462bab4c78 --- /dev/null +++ b/references/nestjs-example/src/app.controller.ts @@ -0,0 +1,31 @@ +import { Controller, Get } from '@nestjs/common'; +import { InjectTriggerDevClient } from '@trigger.dev/nestjs'; +import { eventTrigger, TriggerClient } from '@trigger.dev/sdk'; + +@Controller() +export class AppController { + constructor( + @InjectTriggerDevClient() private readonly client: TriggerClient, + ) { + this.client.defineJob({ + id: 'test-job', + name: 'Test Job One', + version: '0.0.1', + trigger: eventTrigger({ + name: 'test.event', + }), + run: async (payload, io) => { + await io.logger.info('Hello world!', { payload }); + + return { + message: 'Hello world!', + }; + }, + }); + } + + @Get() + getHello(): string { + return `Running Trigger.dev with client-id ${this.client.id}`; + } +} diff --git a/references/nestjs-example/src/app.module.ts b/references/nestjs-example/src/app.module.ts new file mode 100644 index 0000000000..ad5755575b --- /dev/null +++ b/references/nestjs-example/src/app.module.ts @@ -0,0 +1,24 @@ +import { Module } from '@nestjs/common'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { TriggerDevModule } from '@trigger.dev/nestjs'; +import { AppController } from './app.controller'; + +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + }), + TriggerDevModule.registerAsync({ + inject: [ConfigService], + useFactory: (config: ConfigService) => ({ + id: 'my-nest-app', + apiKey: config.getOrThrow('TRIGGER_API_KEY'), + apiUrl: config.getOrThrow('TRIGGER_API_URL'), + verbose: false, + ioLogLocalEnabled: true, + }), + }), + ], + controllers: [AppController], +}) +export class AppModule {} diff --git a/references/nestjs-example/src/main.ts b/references/nestjs-example/src/main.ts new file mode 100644 index 0000000000..13cad38cff --- /dev/null +++ b/references/nestjs-example/src/main.ts @@ -0,0 +1,8 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + await app.listen(3000); +} +bootstrap(); diff --git a/references/nestjs-example/test/app.e2e-spec.ts b/references/nestjs-example/test/app.e2e-spec.ts new file mode 100644 index 0000000000..50cda62332 --- /dev/null +++ b/references/nestjs-example/test/app.e2e-spec.ts @@ -0,0 +1,24 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; +import { AppModule } from './../src/app.module'; + +describe('AppController (e2e)', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + it('/ (GET)', () => { + return request(app.getHttpServer()) + .get('/') + .expect(200) + .expect('Hello World!'); + }); +}); diff --git a/references/nestjs-example/test/jest-e2e.json b/references/nestjs-example/test/jest-e2e.json new file mode 100644 index 0000000000..e9d912f3e3 --- /dev/null +++ b/references/nestjs-example/test/jest-e2e.json @@ -0,0 +1,9 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": ".", + "testEnvironment": "node", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + } +} diff --git a/references/nestjs-example/tsconfig.build.json b/references/nestjs-example/tsconfig.build.json new file mode 100644 index 0000000000..64f86c6bd2 --- /dev/null +++ b/references/nestjs-example/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/references/nestjs-example/tsconfig.json b/references/nestjs-example/tsconfig.json new file mode 100644 index 0000000000..95f5641cf7 --- /dev/null +++ b/references/nestjs-example/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2021", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": false, + "noImplicitAny": false, + "strictBindCallApply": false, + "forceConsistentCasingInFileNames": false, + "noFallthroughCasesInSwitch": false + } +}