diff --git a/examples/framework-nestjs/.eslintrc.js b/examples/framework-nestjs/.eslintrc.js new file mode 100644 index 000000000..259de13c7 --- /dev/null +++ b/examples/framework-nestjs/.eslintrc.js @@ -0,0 +1,25 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir: __dirname, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + root: true, + env: { + node: true, + jest: true, + }, + ignorePatterns: ['.eslintrc.js'], + rules: { + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-explicit-any': 'off', + }, +}; diff --git a/examples/framework-nestjs/.gitignore b/examples/framework-nestjs/.gitignore new file mode 100644 index 000000000..22f55adc5 --- /dev/null +++ b/examples/framework-nestjs/.gitignore @@ -0,0 +1,35 @@ +# compiled output +/dist +/node_modules + +# Logs +logs +*.log +npm-debug.log* +pnpm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store + +# Tests +/coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/examples/framework-nestjs/.prettierrc b/examples/framework-nestjs/.prettierrc new file mode 100644 index 000000000..dcb72794f --- /dev/null +++ b/examples/framework-nestjs/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/examples/framework-nestjs/README.md b/examples/framework-nestjs/README.md new file mode 100644 index 000000000..00a13b112 --- /dev/null +++ b/examples/framework-nestjs/README.md @@ -0,0 +1,73 @@ +

+ Nest Logo +

+ +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest + +

A progressive Node.js framework for building efficient and scalable server-side applications.

+

+NPM Version +Package License +NPM Downloads +CircleCI +Coverage +Discord +Backers on Open Collective +Sponsors on Open Collective + + Support us + +

+ + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ npm install +``` + +## Running the app + +```bash +# development +$ npm run start + +# watch mode +$ npm run start:dev + +# production mode +$ npm run start:prod +``` + +## Test + +```bash +# unit tests +$ npm run test + +# e2e tests +$ npm run test:e2e + +# test coverage +$ npm 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/examples/framework-nestjs/nest-cli.json b/examples/framework-nestjs/nest-cli.json new file mode 100644 index 000000000..f9aa683b1 --- /dev/null +++ b/examples/framework-nestjs/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/examples/framework-nestjs/package.json b/examples/framework-nestjs/package.json new file mode 100644 index 000000000..c602c2684 --- /dev/null +++ b/examples/framework-nestjs/package.json @@ -0,0 +1,71 @@ +{ + "name": "framework-nestjs", + "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", + "dev": "nest start --watch", + "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/platform-express": "^10.0.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.8.1", + "inngest": "^2.0.0" + }, + "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/examples/framework-nestjs/src/app.controller.spec.ts b/examples/framework-nestjs/src/app.controller.spec.ts new file mode 100644 index 000000000..d22f3890a --- /dev/null +++ b/examples/framework-nestjs/src/app.controller.spec.ts @@ -0,0 +1,22 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { AppController } from './app.controller'; +import { AppService } from './app.service'; + +describe('AppController', () => { + let appController: AppController; + + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [AppController], + providers: [AppService], + }).compile(); + + appController = app.get(AppController); + }); + + describe('root', () => { + it('should return "Hello World!"', () => { + expect(appController.getHello()).toBe('Hello World!'); + }); + }); +}); diff --git a/examples/framework-nestjs/src/app.controller.ts b/examples/framework-nestjs/src/app.controller.ts new file mode 100644 index 000000000..cce879ee6 --- /dev/null +++ b/examples/framework-nestjs/src/app.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get } from '@nestjs/common'; +import { AppService } from './app.service'; + +@Controller() +export class AppController { + constructor(private readonly appService: AppService) {} + + @Get() + getHello(): string { + return this.appService.getHello(); + } +} diff --git a/examples/framework-nestjs/src/app.module.ts b/examples/framework-nestjs/src/app.module.ts new file mode 100644 index 000000000..9ba3a8e82 --- /dev/null +++ b/examples/framework-nestjs/src/app.module.ts @@ -0,0 +1,26 @@ +import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; +import { serve } from 'inngest/express'; +import { AppController } from './app.controller'; +import { AppService } from './app.service'; +import { functions, inngest } from './inngest'; + +@Module({ + imports: [], + controllers: [AppController], + providers: [AppService], +}) +export class AppModule implements NestModule { + configure(consumer: MiddlewareConsumer) { + const handler = serve(inngest, functions); + + /** + * NestJS middleware in `main.ts` does not have access to either a parsed or + * raw body, whereas middleware here does. + * + * This means it's critical to add the Inngest handler _here_ so that we can + * appropriately parse the body of incoming requests from Inngest or the + * Inngest dev server. + */ + consumer.apply(handler).forRoutes('/api/inngest'); + } +} diff --git a/examples/framework-nestjs/src/app.service.ts b/examples/framework-nestjs/src/app.service.ts new file mode 100644 index 000000000..927d7cca0 --- /dev/null +++ b/examples/framework-nestjs/src/app.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class AppService { + getHello(): string { + return 'Hello World!'; + } +} diff --git a/examples/framework-nestjs/src/inngest/client.ts b/examples/framework-nestjs/src/inngest/client.ts new file mode 100644 index 000000000..351f31260 --- /dev/null +++ b/examples/framework-nestjs/src/inngest/client.ts @@ -0,0 +1,4 @@ +import { Inngest } from "inngest"; +import { schemas } from "./types"; + +export const inngest = new Inngest({ name: "My Next.js app", schemas }); diff --git a/examples/framework-nestjs/src/inngest/helloWorld.ts b/examples/framework-nestjs/src/inngest/helloWorld.ts new file mode 100644 index 000000000..7de77e041 --- /dev/null +++ b/examples/framework-nestjs/src/inngest/helloWorld.ts @@ -0,0 +1,11 @@ +import { inngest } from "./client"; + +export default inngest.createFunction( + { name: "Hello World" }, + { event: "demo/event.sent" }, + ({ event, step }) => { + return { + message: `Hello ${event.name}!`, + }; + } +); diff --git a/examples/framework-nestjs/src/inngest/index.ts b/examples/framework-nestjs/src/inngest/index.ts new file mode 100644 index 000000000..2315e5f4e --- /dev/null +++ b/examples/framework-nestjs/src/inngest/index.ts @@ -0,0 +1,5 @@ +import helloWorld from "./helloWorld"; + +export const functions = [helloWorld]; + +export { inngest } from "./client"; diff --git a/examples/framework-nestjs/src/inngest/types.ts b/examples/framework-nestjs/src/inngest/types.ts new file mode 100644 index 000000000..bb570b2c0 --- /dev/null +++ b/examples/framework-nestjs/src/inngest/types.ts @@ -0,0 +1,10 @@ +import { EventSchemas } from "inngest"; + +type DemoEventSent = { + name: "demo/event.sent"; + data: { + message: string; + }; +}; + +export const schemas = new EventSchemas().fromUnion(); diff --git a/examples/framework-nestjs/src/main.ts b/examples/framework-nestjs/src/main.ts new file mode 100644 index 000000000..13cad38cf --- /dev/null +++ b/examples/framework-nestjs/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/examples/framework-nestjs/test/app.e2e-spec.ts b/examples/framework-nestjs/test/app.e2e-spec.ts new file mode 100644 index 000000000..50cda6233 --- /dev/null +++ b/examples/framework-nestjs/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/examples/framework-nestjs/test/jest-e2e.json b/examples/framework-nestjs/test/jest-e2e.json new file mode 100644 index 000000000..e9d912f3e --- /dev/null +++ b/examples/framework-nestjs/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/examples/framework-nestjs/tsconfig.build.json b/examples/framework-nestjs/tsconfig.build.json new file mode 100644 index 000000000..64f86c6bd --- /dev/null +++ b/examples/framework-nestjs/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/examples/framework-nestjs/tsconfig.json b/examples/framework-nestjs/tsconfig.json new file mode 100644 index 000000000..95f5641cf --- /dev/null +++ b/examples/framework-nestjs/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 + } +}