├── .eslintignore ├── sample ├── 15-mvc │ ├── public │ │ └── .gitkeep │ ├── tsconfig.build.json │ ├── nodemon.json │ ├── views │ │ └── index.hbs │ ├── src │ │ ├── app.controller.ts │ │ └── app.module.ts │ ├── .gitignore │ └── tsconfig.json ├── 17-mvc-fastify │ ├── public │ │ └── .gitkeep │ ├── tsconfig.build.json │ ├── nodemon.json │ ├── views │ │ └── index.hbs │ ├── src │ │ ├── app.module.ts │ │ └── app.controller.ts │ ├── .gitignore │ └── README.md ├── 25-dynamic-modules │ ├── config │ │ └── development.env │ ├── .prettierrc │ ├── src │ │ ├── config │ │ │ ├── constants.ts │ │ │ └── interfaces │ │ │ │ ├── envconfig.interface.ts │ │ │ │ ├── config-options.interface.ts │ │ │ │ └── index.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── app.module.ts │ │ └── app.service.ts │ ├── nest-cli.json │ └── tsconfig.build.json ├── 09-babel-example │ ├── index.js │ ├── nodemon.json │ ├── jsconfig.json │ ├── src │ │ ├── app.module.js │ │ ├── cats │ │ │ ├── cats.module.js │ │ │ └── cats.service.js │ │ └── main.js │ ├── .gitignore │ └── .babelrc ├── 26-queues │ ├── .prettierrc │ ├── nest-cli.json │ ├── docker-compose.yml │ ├── tsconfig.build.json │ ├── src │ │ ├── app.service.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── app.module.ts │ │ └── audio │ │ │ ├── audio.module.ts │ │ │ └── audio.controller.ts │ └── tsconfig.json ├── 03-microservices │ ├── src │ │ ├── math │ │ │ ├── math.constants.ts │ │ │ └── math.module.ts │ │ ├── app.module.ts │ │ └── common │ │ │ └── filters │ │ │ └── rpc-exception.filter.ts │ ├── tsconfig.build.json │ └── .gitignore ├── 27-scheduling │ ├── .prettierrc │ ├── nest-cli.json │ ├── tsconfig.build.json │ └── src │ │ ├── app.service.ts │ │ ├── tasks │ │ └── tasks.module.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ └── app.module.ts ├── 04-grpc │ ├── nest-cli.json │ ├── src │ │ ├── hero │ │ │ ├── interfaces │ │ │ │ ├── hero-by-id.interface.ts │ │ │ │ └── hero.interface.ts │ │ │ └── hero.proto │ │ ├── app.module.ts │ │ └── grpc-client.options.ts │ ├── tsconfig.build.json │ ├── .gitignore │ └── tsconfig.json ├── 08-webpack │ ├── nest-cli.json │ ├── tsconfig.build.json │ ├── src │ │ ├── app.service.ts │ │ ├── app.module.ts │ │ ├── app.controller.ts │ │ └── main.ts │ └── .gitignore ├── 19-auth-jwt │ ├── src │ │ ├── auth │ │ │ ├── constants.ts │ │ │ └── guards │ │ │ │ ├── jwt-auth.guard.ts │ │ │ │ └── local-auth.guard.ts │ │ ├── app.service.ts │ │ ├── users │ │ │ └── users.module.ts │ │ ├── main.ts │ │ └── app.module.ts │ ├── nodemon.json │ ├── nest-cli.json │ ├── tsconfig.build.json │ └── nodemon-debug.json ├── 11-swagger │ ├── nest-cli.json │ ├── tsconfig.build.json │ ├── src │ │ ├── app.module.ts │ │ └── cats │ │ │ ├── dto │ │ │ └── create-cat.dto.ts │ │ │ ├── cats.module.ts │ │ │ ├── classes │ │ │ └── cat.class.ts │ │ │ └── cats.service.ts │ ├── .gitignore │ └── README.md ├── 12-graphql-schema-first │ ├── nest-cli.json │ ├── tsconfig.build.json │ ├── src │ │ ├── cats │ │ │ ├── dto │ │ │ │ └── create-cat.dto.ts │ │ │ ├── cats.module.ts │ │ │ ├── cats.guard.ts │ │ │ └── cats.graphql │ │ ├── generate-typings.ts │ │ ├── app.module.ts │ │ └── main.ts │ ├── .gitignore │ └── README.md ├── 23-graphql-code-first │ ├── nest-cli.json │ ├── tsconfig.build.json │ ├── .gitignore │ └── src │ │ ├── recipes │ │ ├── dto │ │ │ ├── recipes.args.ts │ │ │ └── new-recipe.input.ts │ │ ├── recipes.module.ts │ │ └── models │ │ │ └── recipe.model.ts │ │ ├── app.module.ts │ │ └── main.ts ├── 05-sql-typeorm │ ├── src │ │ ├── users │ │ │ ├── dto │ │ │ │ └── create-user.dto.ts │ │ │ ├── user.entity.ts │ │ │ └── users.module.ts │ │ └── main.ts │ ├── tsconfig.build.json │ ├── docker-compose.yml │ └── .gitignore ├── 07-sequelize │ ├── src │ │ ├── users │ │ │ ├── dto │ │ │ │ └── create-user.dto.ts │ │ │ ├── user.model.ts │ │ │ └── users.module.ts │ │ └── main.ts │ ├── tsconfig.build.json │ ├── docker-compose.yml │ └── .gitignore ├── 20-cache │ ├── tsconfig.build.json │ ├── src │ │ ├── app.module.ts │ │ ├── app.controller.ts │ │ └── main.ts │ ├── .gitignore │ ├── jest.json │ └── tsconfig.json ├── 01-cats-app │ ├── tsconfig.build.json │ ├── src │ │ ├── cats │ │ │ ├── interfaces │ │ │ │ └── cat.interface.ts │ │ │ ├── dto │ │ │ │ └── create-cat.dto.ts │ │ │ ├── cats.module.ts │ │ │ └── cats.service.ts │ │ ├── common │ │ │ ├── decorators │ │ │ │ └── roles.decorator.ts │ │ │ └── middleware │ │ │ │ └── logger.middleware.ts │ │ ├── app.module.ts │ │ └── main.ts │ ├── .gitignore │ ├── jest.json │ ├── e2e │ │ └── jest-e2e.json │ └── tsconfig.json ├── 02-gateways │ ├── tsconfig.build.json │ ├── src │ │ ├── app.module.ts │ │ ├── events │ │ │ └── events.module.ts │ │ └── main.ts │ ├── .gitignore │ └── tsconfig.json ├── 06-mongoose │ ├── tsconfig.build.json │ ├── src │ │ ├── cats │ │ │ ├── dto │ │ │ │ └── create-cat.dto.ts │ │ │ └── schemas │ │ │ │ └── cat.schema.ts │ │ ├── main.ts │ │ └── app.module.ts │ ├── docker-compose.yml │ └── .gitignore ├── 10-fastify │ ├── tsconfig.build.json │ ├── src │ │ ├── cats │ │ │ ├── interfaces │ │ │ │ └── cat.interface.ts │ │ │ ├── dto │ │ │ │ └── create-cat.dto.ts │ │ │ ├── cats.module.ts │ │ │ └── cats.service.ts │ │ ├── common │ │ │ ├── decorators │ │ │ │ └── roles.decorator.ts │ │ │ └── middleware │ │ │ │ └── logger.middleware.ts │ │ └── app.module.ts │ ├── .gitignore │ └── README.md ├── 18-context │ ├── tsconfig.build.json │ ├── src │ │ ├── app.service.ts │ │ ├── app.module.ts │ │ └── main.ts │ └── .gitignore ├── 21-serializer │ ├── tsconfig.build.json │ ├── src │ │ ├── entities │ │ │ └── role.entity.ts │ │ ├── app.module.ts │ │ └── main.ts │ ├── .gitignore │ └── jest.json ├── 13-mongo-typeorm │ ├── tsconfig.build.json │ ├── docker-compose.yml │ ├── .gitignore │ └── src │ │ ├── main.ts │ │ └── photo │ │ ├── photo.entity.ts │ │ ├── photo.controller.ts │ │ └── photo.module.ts ├── 14-mongoose-base │ ├── tsconfig.build.json │ ├── src │ │ ├── cats │ │ │ ├── dto │ │ │ │ └── create-cat.dto.ts │ │ │ ├── schemas │ │ │ │ └── cat.schema.ts │ │ │ ├── interfaces │ │ │ │ └── cat.interface.ts │ │ │ ├── cats.providers.ts │ │ │ └── cats.module.ts │ │ ├── app.module.ts │ │ ├── database │ │ │ ├── database.module.ts │ │ │ └── database.providers.ts │ │ └── main.ts │ ├── docker-compose.yml │ └── .gitignore ├── 16-gateways-ws │ ├── tsconfig.build.json │ ├── src │ │ ├── app.module.ts │ │ ├── events │ │ │ └── events.module.ts │ │ └── main.ts │ └── .gitignore ├── 22-graphql-prisma │ ├── tsconfig.build.json │ ├── database │ │ └── datamodel.graphql │ ├── nodemon.json │ ├── src │ │ ├── prisma │ │ │ ├── prisma.module.ts │ │ │ └── prisma.service.ts │ │ ├── posts │ │ │ └── posts.module.ts │ │ └── main.ts │ └── .graphqlconfig.yml └── 24-serve-static │ ├── tsconfig.build.json │ ├── src │ ├── app.controller.ts │ ├── main.ts │ └── app.module.ts │ ├── client │ └── index.html │ └── .gitignore ├── benchmarks ├── nest │ ├── main.d.ts │ ├── app.module.d.ts │ ├── app.controller.d.ts │ ├── main.js.map │ ├── app.module.js.map │ └── app.controller.js.map ├── fastify.js ├── express.js └── nest.js ├── .prettierignore ├── packages ├── core │ ├── router │ │ ├── index.ts │ │ ├── request │ │ │ ├── index.ts │ │ │ ├── request-constants.ts │ │ │ └── request-providers.ts │ │ └── interfaces │ │ │ ├── resolver.interface.ts │ │ │ └── route-params-factory.interface.ts │ ├── adapters │ │ └── index.ts │ ├── middleware │ │ └── index.ts │ ├── services │ │ └── index.ts │ ├── exceptions │ │ └── index.ts │ ├── injector │ │ ├── inquirer │ │ │ ├── index.ts │ │ │ ├── inquirer-constants.ts │ │ │ └── inquirer-providers.ts │ │ ├── modules-container.ts │ │ ├── index.ts │ │ └── constants.ts │ ├── guards │ │ └── constants.ts │ ├── PACKAGE.md │ ├── discovery │ │ ├── index.ts │ │ └── discovery-module.ts │ ├── helpers │ │ ├── index.ts │ │ ├── interfaces │ │ │ ├── index.ts │ │ │ └── params-metadata.interface.ts │ │ ├── optional-require.ts │ │ └── get-class-scope.ts │ ├── test │ │ ├── utils │ │ │ └── string.cleaner.ts │ │ └── helpers │ │ │ ├── context-id-factory.spec.ts │ │ │ └── application-ref-host.spec.ts │ ├── tsconfig.json │ ├── errors │ │ └── exceptions │ │ │ ├── runtime.exception.ts │ │ │ ├── invalid-class.exception.ts │ │ │ ├── unknown-request-mapping.exception.ts │ │ │ ├── invalid-exception-filter.exception.ts │ │ │ ├── unknown-module.exception.ts │ │ │ ├── invalid-middleware.exception.ts │ │ │ ├── invalid-middleware-configuration.exception.ts │ │ │ ├── unknown-export.exception.ts │ │ │ ├── invalid-module.exception.ts │ │ │ ├── undefined-module.exception.ts │ │ │ ├── undefined-forwardref.exception.ts │ │ │ ├── unknown-element.exception.ts │ │ │ └── circular-dependency.exception.ts │ └── hooks │ │ └── index.ts ├── common │ ├── services │ │ └── index.ts │ ├── utils │ │ ├── index.ts │ │ ├── random-string-generator.util.ts │ │ ├── forward-ref.util.ts │ │ └── extend-metadata.util.ts │ ├── cache │ │ ├── interceptors │ │ │ └── index.ts │ │ ├── decorators │ │ │ └── index.ts │ │ ├── interfaces │ │ │ └── index.ts │ │ ├── default-options.ts │ │ ├── index.ts │ │ └── cache.constants.ts │ ├── http │ │ ├── interfaces │ │ │ └── index.ts │ │ ├── index.ts │ │ └── http.constants.ts │ ├── interfaces │ │ ├── injectable.interface.ts │ │ ├── controllers │ │ │ ├── controller.interface.ts │ │ │ ├── controller-metadata.interface.ts │ │ │ └── index.ts │ │ ├── abstract.interface.ts │ │ ├── features │ │ │ ├── paramtype.interface.ts │ │ │ └── custom-route-param-factory.interface.ts │ │ ├── type.interface.ts │ │ ├── modules │ │ │ ├── forward-reference.interface.ts │ │ │ ├── nest-module.interface.ts │ │ │ ├── introspection-result.interface.ts │ │ │ └── index.ts │ │ ├── microservices │ │ │ ├── nest-hybrid-application-options.interface.ts │ │ │ └── nest-microservice-options.interface.ts │ │ ├── hooks │ │ │ ├── before-application-shutdown.interface.ts │ │ │ ├── index.ts │ │ │ ├── on-init.interface.ts │ │ │ ├── on-application-bootstrap.interface.ts │ │ │ ├── on-application-shutdown.interface.ts │ │ │ └── on-destroy.interface.ts │ │ ├── middleware │ │ │ ├── nest-middleware.interface.ts │ │ │ ├── index.ts │ │ │ └── middleware-configuration.interface.ts │ │ ├── exceptions │ │ │ ├── exception-filter-metadata.interface.ts │ │ │ ├── index.ts │ │ │ └── rpc-exception-filter-metadata.interface.ts │ │ └── nest-application-context-options.interface.ts │ ├── serializer │ │ ├── decorators │ │ │ ├── index.ts │ │ │ └── serialize-options.decorator.ts │ │ ├── index.ts │ │ └── class-serializer.constants.ts │ ├── PACKAGE.md │ ├── decorators │ │ ├── index.ts │ │ ├── modules │ │ │ └── index.ts │ │ └── http │ │ │ └── index.ts │ ├── enums │ │ ├── index.ts │ │ ├── request-method.enum.ts │ │ ├── route-paramtypes.enum.ts │ │ └── shutdown-signal.enum.ts │ ├── tsconfig.json │ ├── pipes │ │ └── index.ts │ └── test │ │ ├── utils │ │ ├── random-string-generator.util.spec.ts │ │ └── forward-ref.util.spec.ts │ │ └── decorators │ │ └── global.decorator.spec.ts ├── platform-ws │ ├── adapters │ │ └── index.ts │ ├── tsconfig.json │ └── index.ts ├── websockets │ ├── adapters │ │ └── index.ts │ ├── errors │ │ ├── index.ts │ │ └── invalid-socket-port.exception.ts │ ├── utils │ │ ├── index.ts │ │ └── compare-element.util.ts │ ├── exceptions │ │ └── index.ts │ ├── enums │ │ └── ws-paramtype.enum.ts │ ├── interfaces │ │ ├── ws-response.interface.ts │ │ ├── hooks │ │ │ ├── on-gateway-init.interface.ts │ │ │ ├── on-gateway-disconnect.interface.ts │ │ │ ├── on-gateway-connection.interface.ts │ │ │ └── index.ts │ │ ├── web-socket-server.interface.ts │ │ ├── nest-gateway.interface.ts │ │ ├── index.ts │ │ └── socket-events-host.interface.ts │ ├── tsconfig.json │ ├── decorators │ │ ├── index.ts │ │ ├── connected-socket.decorator.ts │ │ └── gateway-server.decorator.ts │ ├── context │ │ └── ws-metadata-constants.ts │ └── index.ts ├── platform-express │ ├── adapters │ │ └── index.ts │ ├── interfaces │ │ └── index.ts │ ├── multer │ │ ├── interfaces │ │ │ └── index.ts │ │ ├── multer.constants.ts │ │ ├── files.constants.ts │ │ ├── index.ts │ │ ├── interceptors │ │ │ └── index.ts │ │ └── multer │ │ │ └── multer.constants.ts │ ├── tsconfig.json │ └── index.ts ├── platform-fastify │ ├── adapters │ │ └── index.ts │ ├── interfaces │ │ └── index.ts │ ├── tsconfig.json │ └── index.ts ├── platform-socket.io │ ├── adapters │ │ └── index.ts │ ├── tsconfig.json │ └── index.ts ├── microservices │ ├── test │ │ ├── server │ │ │ ├── test.proto │ │ │ └── test2.proto │ │ └── client │ │ │ ├── test.proto │ │ │ └── test2.proto │ ├── utils │ │ └── index.ts │ ├── module │ │ ├── interfaces │ │ │ └── index.ts │ │ └── index.ts │ ├── enums │ │ ├── index.ts │ │ ├── pattern-handler.enum.ts │ │ ├── rpc-paramtype.enum.ts │ │ └── transport.enum.ts │ ├── interfaces │ │ ├── closeable.interface.ts │ │ ├── pattern-metadata.interface.ts │ │ ├── client-grpc.interface.ts │ │ ├── custom-transport-strategy.interface.ts │ │ ├── message-handler.interface.ts │ │ ├── pattern.interface.ts │ │ ├── request-context.interface.ts │ │ └── serializer.interface.ts │ ├── tokens.ts │ ├── exceptions │ │ └── index.ts │ ├── tsconfig.json │ ├── errors │ │ ├── net-socket-closed.exception.ts │ │ ├── invalid-json-format.exception.ts │ │ ├── corrupted-packet-length.exception.ts │ │ ├── invalid-grpc-package.exception.ts │ │ ├── invalid-grpc-service.exception.ts │ │ ├── invalid-message.exception.ts │ │ ├── invalid-proto-definition.exception.ts │ │ ├── invalid-kafka-client-topic.exception.ts │ │ └── invalid-kafka-client-topic-partition.exception.ts │ ├── helpers │ │ └── index.ts │ ├── client │ │ ├── constants.ts │ │ └── index.ts │ ├── ctx-host │ │ ├── index.ts │ │ ├── nats.context.ts │ │ └── redis.context.ts │ ├── serializers │ │ └── identity.serializer.ts │ ├── deserializers │ │ └── identity.deserializer.ts │ ├── decorators │ │ ├── ctx.decorator.ts │ │ ├── index.ts │ │ └── grpc-service.decorator.ts │ ├── server │ │ └── index.ts │ └── context │ │ └── rpc-metadata-constants.ts ├── index.ts └── testing │ ├── interfaces │ ├── index.ts │ ├── override-by-factory-options.interface.ts │ └── override-by.interface.ts │ ├── tsconfig.json │ └── index.ts ├── scripts ├── test.sh ├── prepare.sh └── run-integration.sh ├── .gitattributes ├── .prettierrc ├── lerna.json ├── .github └── FUNDING.yml ├── integration ├── injector │ └── src │ │ ├── defaults │ │ ├── core.service.ts │ │ ├── defaults.module.ts │ │ └── defaults.service.ts │ │ ├── inject │ │ ├── core.service.ts │ │ ├── inject.module.ts │ │ └── inject.service.ts │ │ ├── exports │ │ ├── exports.service.ts │ │ └── exports.module.ts │ │ ├── properties │ │ ├── dependency.service.ts │ │ └── properties.service.ts │ │ ├── core-injectables │ │ └── core-injectables.module.ts │ │ ├── circular-structure-dynamic-module │ │ ├── input.service.ts │ │ └── circular.module.ts │ │ ├── scoped │ │ ├── scoped.controller.ts │ │ ├── transient2.service.ts │ │ ├── scoped.service.ts │ │ ├── transient.service.ts │ │ └── transient3.service.ts │ │ ├── app.module.ts │ │ ├── circular │ │ ├── circular.module.ts │ │ ├── circular.service.ts │ │ └── input.service.ts │ │ ├── circular-properties │ │ ├── circular.service.ts │ │ ├── input.service.ts │ │ ├── input-properties.module.ts │ │ └── circular-properties.module.ts │ │ └── circular-modules │ │ ├── circular.service.ts │ │ ├── input.service.ts │ │ ├── input.module.ts │ │ └── circular.module.ts ├── microservices │ └── src │ │ ├── grpc-advanced │ │ └── proto │ │ │ ├── root.proto │ │ │ ├── common │ │ │ ├── item_types.proto │ │ │ └── shipment_types.proto │ │ │ └── orders │ │ │ ├── message.proto │ │ │ └── service.proto │ │ ├── kafka │ │ └── dtos │ │ │ ├── user.dto.ts │ │ │ └── business.dto.ts │ │ ├── main.ts │ │ └── grpc │ │ ├── math2.proto │ │ └── math.proto ├── mongoose │ └── src │ │ ├── cats │ │ ├── dto │ │ │ └── create-cat.dto.ts │ │ ├── schemas │ │ │ └── cat.schema.ts │ │ └── interfaces │ │ │ └── cat.interface.ts │ │ ├── main.ts │ │ └── app.module.ts ├── graphql-schema-first │ └── src │ │ ├── cats │ │ ├── interfaces │ │ │ └── cat.interface.ts │ │ ├── cats.types.graphql │ │ └── cats.guard.ts │ │ ├── config.module.ts │ │ ├── main.ts │ │ ├── config.service.ts │ │ └── app.module.ts ├── hello-world │ └── src │ │ ├── hello │ │ ├── hello.service.ts │ │ ├── users │ │ │ ├── users.service.ts │ │ │ └── user-by-id.pipe.ts │ │ ├── dto │ │ │ └── test.dto.ts │ │ └── hello.module.ts │ │ ├── host │ │ ├── host.service.ts │ │ ├── users │ │ │ ├── users.service.ts │ │ │ └── user-by-id.pipe.ts │ │ ├── dto │ │ │ └── test.dto.ts │ │ └── host.module.ts │ │ └── app.module.ts ├── nest-application │ └── get-url │ │ ├── src │ │ ├── app.service.ts │ │ ├── app.module.ts │ │ └── app.controller.ts │ │ └── e2e │ │ └── utils.ts ├── websockets │ └── src │ │ ├── app.module.ts │ │ ├── ack.gateway.ts │ │ ├── server.gateway.ts │ │ ├── namespace.gateway.ts │ │ ├── app.gateway.ts │ │ ├── error.gateway.ts │ │ └── core.gateway.ts ├── scopes │ └── src │ │ ├── hello │ │ ├── dto │ │ │ └── test.dto.ts │ │ ├── hello.service.ts │ │ └── users │ │ │ └── users.service.ts │ │ ├── msvc │ │ ├── dto │ │ │ └── test.dto.ts │ │ ├── hello.service.ts │ │ ├── users │ │ │ └── users.service.ts │ │ └── http.controller.ts │ │ ├── transient │ │ ├── dto │ │ │ └── test.dto.ts │ │ ├── hello.service.ts │ │ └── users │ │ │ ├── users.service.ts │ │ │ └── user-by-id.pipe.ts │ │ ├── app.module.ts │ │ ├── circular-hello │ │ ├── dto │ │ │ └── test.dto.ts │ │ ├── hello.service.ts │ │ └── users │ │ │ └── users.service.ts │ │ ├── circular-transient │ │ ├── dto │ │ │ └── test.dto.ts │ │ ├── hello.service.ts │ │ └── users │ │ │ ├── users.service.ts │ │ │ └── user-by-id.pipe.ts │ │ ├── main.ts │ │ ├── request-chain │ │ ├── helper │ │ │ ├── helper.module.ts │ │ │ └── helper.service.ts │ │ ├── request-chain.service.ts │ │ └── request-chain.module.ts │ │ ├── resolve-scoped │ │ ├── logger.service.ts │ │ ├── request-logger.service.ts │ │ └── logger.provider.ts │ │ └── inject-inquirer │ │ └── hello-transient │ │ └── hello-transient.service.ts ├── typeorm │ ├── ormconfig.json │ └── src │ │ ├── main.ts │ │ ├── app-async.module.ts │ │ └── photo │ │ ├── photo.entity.ts │ │ └── photo.module.ts └── graphql-code-first │ └── src │ ├── recipes │ ├── dto │ │ └── recipes.args.ts │ └── models │ │ └── recipe.ts │ ├── main.ts │ └── common │ └── filters │ └── unauthorized.filter.ts ├── tsconfig.spec.json ├── tools └── gulp │ ├── gulpfile.ts │ ├── config.ts │ └── util │ └── task-helpers.ts ├── .npmignore ├── renovate.json ├── .eslintrc.spec.js ├── .circleci └── install-wrk.sh └── gulpfile.js /.eslintignore: -------------------------------------------------------------------------------- 1 | **/node_modules/** -------------------------------------------------------------------------------- /sample/15-mvc/public/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/17-mvc-fastify/public/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /benchmarks/nest/main.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | packages/**/*.d.ts 2 | packages/**/*.js -------------------------------------------------------------------------------- /packages/core/router/index.ts: -------------------------------------------------------------------------------- 1 | export * from './request'; 2 | -------------------------------------------------------------------------------- /packages/core/adapters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './http-adapter'; 2 | -------------------------------------------------------------------------------- /packages/core/middleware/index.ts: -------------------------------------------------------------------------------- 1 | export * from './builder'; 2 | -------------------------------------------------------------------------------- /benchmarks/nest/app.module.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppModule {} 2 | -------------------------------------------------------------------------------- /packages/common/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './logger.service'; 2 | -------------------------------------------------------------------------------- /packages/common/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './forward-ref.util'; 2 | -------------------------------------------------------------------------------- /packages/core/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './reflector.service'; 2 | -------------------------------------------------------------------------------- /packages/platform-ws/adapters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ws-adapter'; 2 | -------------------------------------------------------------------------------- /packages/websockets/adapters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ws-adapter'; 2 | -------------------------------------------------------------------------------- /packages/websockets/errors/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ws-exception'; 2 | -------------------------------------------------------------------------------- /packages/websockets/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './param.utils'; 2 | -------------------------------------------------------------------------------- /packages/core/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base-exception-filter'; 2 | -------------------------------------------------------------------------------- /packages/core/injector/inquirer/index.ts: -------------------------------------------------------------------------------- 1 | export * from './inquirer-constants'; 2 | -------------------------------------------------------------------------------- /packages/platform-express/adapters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './express-adapter'; 2 | -------------------------------------------------------------------------------- /packages/platform-fastify/adapters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './fastify-adapter'; 2 | -------------------------------------------------------------------------------- /packages/platform-socket.io/adapters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './io-adapter'; 2 | -------------------------------------------------------------------------------- /packages/common/cache/interceptors/index.ts: -------------------------------------------------------------------------------- 1 | export * from './cache.interceptor'; 2 | -------------------------------------------------------------------------------- /packages/common/http/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './http-module.interface'; 2 | -------------------------------------------------------------------------------- /packages/common/interfaces/injectable.interface.ts: -------------------------------------------------------------------------------- 1 | export type Injectable = unknown; 2 | -------------------------------------------------------------------------------- /packages/core/router/request/index.ts: -------------------------------------------------------------------------------- 1 | export { REQUEST } from './request-constants'; 2 | -------------------------------------------------------------------------------- /packages/microservices/test/server/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test; -------------------------------------------------------------------------------- /packages/microservices/test/server/test2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test2; -------------------------------------------------------------------------------- /packages/microservices/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './transform-pattern.utils'; 2 | -------------------------------------------------------------------------------- /packages/websockets/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base-ws-exception-filter'; 2 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/config/development.env: -------------------------------------------------------------------------------- 1 | HELLO_MESSAGE = 'Hello there, world!' -------------------------------------------------------------------------------- /packages/core/guards/constants.ts: -------------------------------------------------------------------------------- 1 | export const FORBIDDEN_MESSAGE = 'Forbidden resource'; 2 | -------------------------------------------------------------------------------- /packages/core/injector/inquirer/inquirer-constants.ts: -------------------------------------------------------------------------------- 1 | export const INQUIRER = 'INQUIRER'; 2 | -------------------------------------------------------------------------------- /sample/09-babel-example/index.js: -------------------------------------------------------------------------------- 1 | require('@babel/register'); 2 | require('./src/main'); 3 | -------------------------------------------------------------------------------- /sample/26-queues/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /packages/common/serializer/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './serialize-options.decorator'; 2 | -------------------------------------------------------------------------------- /packages/microservices/module/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './clients-module.interface'; 2 | -------------------------------------------------------------------------------- /sample/03-microservices/src/math/math.constants.ts: -------------------------------------------------------------------------------- 1 | export const MATH_SERVICE = 'MATH_SERVICE'; 2 | -------------------------------------------------------------------------------- /sample/27-scheduling/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | # Run both unit and integration tests 2 | npm run test 3 | npm run test:integration -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | package-lock.json -diff -merge 2 | package-lock.json linguist-generated=true 3 | -------------------------------------------------------------------------------- /packages/common/interfaces/controllers/controller.interface.ts: -------------------------------------------------------------------------------- 1 | export type Controller = object; 2 | -------------------------------------------------------------------------------- /packages/core/PACKAGE.md: -------------------------------------------------------------------------------- 1 | Implements Nest's core functionality, low-level services, and utilities. 2 | -------------------------------------------------------------------------------- /packages/platform-express/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './nest-express-application.interface'; 2 | -------------------------------------------------------------------------------- /packages/platform-fastify/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './nest-fastify-application.interface'; 2 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/config/constants.ts: -------------------------------------------------------------------------------- 1 | export const CONFIG_OPTIONS = 'CONFIG_OPTIONS'; 2 | -------------------------------------------------------------------------------- /benchmarks/nest/app.controller.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppController { 2 | root(): string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/platform-express/multer/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './files-upload-module.interface'; 2 | -------------------------------------------------------------------------------- /packages/platform-express/multer/multer.constants.ts: -------------------------------------------------------------------------------- 1 | export const MULTER_MODULE_ID = 'MULTER_MODULE_ID'; 2 | -------------------------------------------------------------------------------- /sample/04-grpc/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "assets": ["**/*.proto"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/08-webpack/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "deleteOutDir": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/auth/constants.ts: -------------------------------------------------------------------------------- 1 | export const jwtConstants = { 2 | secret: 'secretKey', 3 | }; 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "arrowParens": "avoid", 4 | "trailingComma": "all" 5 | } 6 | -------------------------------------------------------------------------------- /packages/core/discovery/index.ts: -------------------------------------------------------------------------------- 1 | export * from './discovery-module'; 2 | export * from './discovery-service'; 3 | -------------------------------------------------------------------------------- /packages/core/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './context-id-factory'; 2 | export * from './http-adapter-host'; 3 | -------------------------------------------------------------------------------- /packages/microservices/module/index.ts: -------------------------------------------------------------------------------- 1 | export * from './clients.module'; 2 | export * from './interfaces'; 3 | -------------------------------------------------------------------------------- /packages/microservices/enums/index.ts: -------------------------------------------------------------------------------- 1 | export * from './transport.enum'; 2 | export * from './kafka-headers.enum'; 3 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/closeable.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Closeable { 2 | close(): void; 3 | } 4 | -------------------------------------------------------------------------------- /packages/microservices/tokens.ts: -------------------------------------------------------------------------------- 1 | import { REQUEST } from '@nestjs/core'; 2 | 3 | export const CONTEXT = REQUEST; 4 | -------------------------------------------------------------------------------- /packages/platform-express/multer/files.constants.ts: -------------------------------------------------------------------------------- 1 | export const MULTER_MODULE_OPTIONS = 'MULTER_MODULE_OPTIONS'; 2 | -------------------------------------------------------------------------------- /sample/04-grpc/src/hero/interfaces/hero-by-id.interface.ts: -------------------------------------------------------------------------------- 1 | export interface HeroById { 2 | id: number; 3 | } 4 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["dist"], 3 | "ext": "js", 4 | "exec": "node dist/main" 5 | } 6 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "2.4.0", 3 | "packages": [ 4 | "packages/*" 5 | ], 6 | "version": "7.3.1" 7 | } 8 | -------------------------------------------------------------------------------- /packages/common/PACKAGE.md: -------------------------------------------------------------------------------- 1 | The common package comes with decorators such as `@Controller()`, `@Injectable()` and so on. 2 | -------------------------------------------------------------------------------- /packages/common/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './core'; 2 | export * from './modules'; 3 | export * from './http'; 4 | -------------------------------------------------------------------------------- /packages/common/decorators/modules/index.ts: -------------------------------------------------------------------------------- 1 | export * from './global.decorator'; 2 | export * from './module.decorator'; 3 | -------------------------------------------------------------------------------- /packages/common/serializer/index.ts: -------------------------------------------------------------------------------- 1 | export * from './class-serializer.interceptor'; 2 | export * from './decorators'; 3 | -------------------------------------------------------------------------------- /packages/websockets/enums/ws-paramtype.enum.ts: -------------------------------------------------------------------------------- 1 | export enum WsParamtype { 2 | SOCKET = 0, 3 | PAYLOAD = 3, 4 | } 5 | -------------------------------------------------------------------------------- /packages/common/cache/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './cache-key.decorator'; 2 | export * from './cache-ttl.decorator'; 3 | -------------------------------------------------------------------------------- /packages/common/interfaces/abstract.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Abstract extends Function { 2 | prototype: T; 3 | } 4 | -------------------------------------------------------------------------------- /packages/common/interfaces/features/paramtype.interface.ts: -------------------------------------------------------------------------------- 1 | export type Paramtype = 'body' | 'query' | 'param' | 'custom'; 2 | -------------------------------------------------------------------------------- /packages/common/serializer/class-serializer.constants.ts: -------------------------------------------------------------------------------- 1 | export const CLASS_SERIALIZER_OPTIONS = 'class_serializer:options'; 2 | -------------------------------------------------------------------------------- /packages/microservices/enums/pattern-handler.enum.ts: -------------------------------------------------------------------------------- 1 | export enum PatternHandler { 2 | MESSAGE = 1, 3 | EVENT = 2, 4 | } 5 | -------------------------------------------------------------------------------- /packages/microservices/enums/rpc-paramtype.enum.ts: -------------------------------------------------------------------------------- 1 | export enum RpcParamtype { 2 | PAYLOAD = 3, 3 | CONTEXT = 6, 4 | } 5 | -------------------------------------------------------------------------------- /packages/microservices/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './base-rpc-exception-filter'; 2 | export * from './rpc-exception'; 3 | -------------------------------------------------------------------------------- /sample/04-grpc/src/hero/interfaces/hero.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Hero { 2 | id: number; 3 | name: string; 4 | } 5 | -------------------------------------------------------------------------------- /sample/11-swagger/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "plugins": ["@nestjs/swagger/plugin"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "assets": ["**/*.graphql"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [kamilmysliwiec] 4 | open_collective: nest 5 | -------------------------------------------------------------------------------- /packages/common/interfaces/type.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Type extends Function { 2 | new (...args: any[]): T; 3 | } 4 | -------------------------------------------------------------------------------- /packages/microservices/test/client/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test; 4 | 5 | service TestService { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /packages/common/cache/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './cache-manager.interface'; 2 | export * from './cache-module.interface'; 3 | -------------------------------------------------------------------------------- /packages/common/http/index.ts: -------------------------------------------------------------------------------- 1 | export * from './http.module'; 2 | export * from './http.service'; 3 | export * from './interfaces'; 4 | -------------------------------------------------------------------------------- /packages/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/pattern-metadata.interface.ts: -------------------------------------------------------------------------------- 1 | export interface PatternMetadata { 2 | [prop: string]: any; 3 | } 4 | -------------------------------------------------------------------------------- /packages/microservices/test/client/test2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test2; 4 | 5 | service TestService { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "plugins": ["@nestjs/graphql/plugin"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/config/interfaces/envconfig.interface.ts: -------------------------------------------------------------------------------- 1 | export interface EnvConfig { 2 | [key: string]: string; 3 | } 4 | -------------------------------------------------------------------------------- /sample/26-queues/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /sample/27-scheduling/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /packages/common/cache/default-options.ts: -------------------------------------------------------------------------------- 1 | export const defaultCacheOptions = { 2 | ttl: 5, 3 | max: 100, 4 | store: 'memory', 5 | }; 6 | -------------------------------------------------------------------------------- /packages/common/interfaces/controllers/controller-metadata.interface.ts: -------------------------------------------------------------------------------- 1 | export interface ControllerMetadata { 2 | path?: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/common/interfaces/modules/forward-reference.interface.ts: -------------------------------------------------------------------------------- 1 | export interface ForwardReference { 2 | forwardRef: T; 3 | } 4 | -------------------------------------------------------------------------------- /packages/testing/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './override-by-factory-options.interface'; 2 | export * from './override-by.interface'; 3 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/ws-response.interface.ts: -------------------------------------------------------------------------------- 1 | export interface WsResponse { 2 | event: string; 3 | data: T; 4 | } 5 | -------------------------------------------------------------------------------- /sample/05-sql-typeorm/src/users/dto/create-user.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateUserDto { 2 | firstName: string; 3 | lastName: string; 4 | } 5 | -------------------------------------------------------------------------------- /sample/07-sequelize/src/users/dto/create-user.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateUserDto { 2 | firstName: string; 3 | lastName: string; 4 | } 5 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/config/interfaces/config-options.interface.ts: -------------------------------------------------------------------------------- 1 | export interface ConfigOptions { 2 | folder: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/common/interfaces/controllers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './controller-metadata.interface'; 2 | export * from './controller.interface'; 3 | -------------------------------------------------------------------------------- /packages/platform-express/multer/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interceptors'; 2 | export * from './interfaces'; 3 | export * from './multer.module'; 4 | -------------------------------------------------------------------------------- /sample/04-grpc/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/15-mvc/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/20-cache/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/config/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './envconfig.interface'; 2 | export * from './config-options.interface'; 3 | -------------------------------------------------------------------------------- /sample/26-queues/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | redis: 4 | image: redis:alpine 5 | ports: 6 | - 6379:6379 7 | -------------------------------------------------------------------------------- /integration/injector/src/defaults/core.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class CoreService {} 5 | -------------------------------------------------------------------------------- /integration/injector/src/inject/core.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class CoreService {} 5 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc-advanced/proto/root.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package proto_example; 3 | import public "orders/service.proto"; 4 | -------------------------------------------------------------------------------- /packages/common/utils/random-string-generator.util.ts: -------------------------------------------------------------------------------- 1 | import { v4 as uuid } from 'uuid'; 2 | 3 | export const randomStringGenerator = () => uuid(); 4 | -------------------------------------------------------------------------------- /packages/core/helpers/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './external-handler-metadata.interface'; 2 | export * from './params-metadata.interface'; 3 | -------------------------------------------------------------------------------- /packages/core/injector/modules-container.ts: -------------------------------------------------------------------------------- 1 | import { Module } from './module'; 2 | 3 | export class ModulesContainer extends Map {} 4 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/hooks/on-gateway-init.interface.ts: -------------------------------------------------------------------------------- 1 | export interface OnGatewayInit { 2 | afterInit(server: T): any; 3 | } 4 | -------------------------------------------------------------------------------- /sample/01-cats-app/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/02-gateways/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/06-mongoose/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/07-sequelize/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/08-webpack/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/10-fastify/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/11-swagger/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/18-context/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/21-serializer/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/26-queues/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/27-scheduling/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /integration/injector/src/exports/exports.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class ExportsService {} 5 | -------------------------------------------------------------------------------- /packages/common/enums/index.ts: -------------------------------------------------------------------------------- 1 | export * from './request-method.enum'; 2 | export * from './http-status.enum'; 3 | export * from './shutdown-signal.enum'; 4 | -------------------------------------------------------------------------------- /packages/core/router/request/request-constants.ts: -------------------------------------------------------------------------------- 1 | export const REQUEST = 'REQUEST'; 2 | export const REQUEST_CONTEXT_ID = Symbol('REQUEST_CONTEXT_ID'); 3 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/web-socket-server.interface.ts: -------------------------------------------------------------------------------- 1 | export interface WebSocketServerOptions { 2 | port: number; 3 | namespace: string; 4 | } 5 | -------------------------------------------------------------------------------- /sample/03-microservices/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/05-sql-typeorm/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/15-mvc/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/**/*.spec.ts"], 5 | "exec": "ts-node ./src/main" 6 | } 7 | -------------------------------------------------------------------------------- /sample/16-gateways-ws/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/17-mvc-fastify/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/24-serve-static/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /sample/17-mvc-fastify/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/**/*.spec.ts"], 5 | "exec": "ts-node ./src/main" 6 | } 7 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["integration/**/*", "**/*.spec.ts"], 4 | "exclude": ["node_modules", "dist"] 5 | } 6 | -------------------------------------------------------------------------------- /integration/injector/src/properties/dependency.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class DependencyService {} 5 | -------------------------------------------------------------------------------- /integration/microservices/src/kafka/dtos/user.dto.ts: -------------------------------------------------------------------------------- 1 | export class UserDto { 2 | name: string; 3 | email: string; 4 | phone: string; 5 | years: number; 6 | } 7 | -------------------------------------------------------------------------------- /packages/core/test/utils/string.cleaner.ts: -------------------------------------------------------------------------------- 1 | export function stringCleaner(str: string) { 2 | return str ? str.replace(/\s+/g, '').replace(/\n+/g, '') : str; 3 | } 4 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/hooks/on-gateway-disconnect.interface.ts: -------------------------------------------------------------------------------- 1 | export interface OnGatewayDisconnect { 2 | handleDisconnect(client: T): any; 3 | } 4 | -------------------------------------------------------------------------------- /tools/gulp/gulpfile.ts: -------------------------------------------------------------------------------- 1 | import './tasks/copy-misc'; 2 | import './tasks/clean'; 3 | import './tasks/packages'; 4 | import './tasks/move'; 5 | import './tasks/samples'; 6 | -------------------------------------------------------------------------------- /integration/injector/src/core-injectables/core-injectables.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | 3 | @Module({}) 4 | export class CoreInjectablesModule {} 5 | -------------------------------------------------------------------------------- /integration/mongoose/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateCatDto { 2 | readonly name: string; 3 | readonly age: number; 4 | readonly breed: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/common/interfaces/microservices/nest-hybrid-application-options.interface.ts: -------------------------------------------------------------------------------- 1 | export interface NestHybridApplicationOptions { 2 | inheritAppConfig?: boolean; 3 | } 4 | -------------------------------------------------------------------------------- /packages/microservices/enums/transport.enum.ts: -------------------------------------------------------------------------------- 1 | export enum Transport { 2 | TCP, 3 | REDIS, 4 | NATS, 5 | MQTT, 6 | GRPC, 7 | RMQ, 8 | KAFKA, 9 | } 10 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/cats/interfaces/cat.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Cat { 2 | readonly name: string; 3 | readonly age: number; 4 | readonly breed: string; 5 | } 6 | -------------------------------------------------------------------------------- /sample/06-mongoose/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateCatDto { 2 | readonly name: string; 3 | readonly age: number; 4 | readonly breed: string; 5 | } 6 | -------------------------------------------------------------------------------- /sample/09-babel-example/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "js", 4 | "ignore": ["src/**/*.spec.js"], 5 | "exec": "node index --exec babel-node" 6 | } 7 | -------------------------------------------------------------------------------- /sample/10-fastify/src/cats/interfaces/cat.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Cat { 2 | readonly name: string; 3 | readonly age: number; 4 | readonly breed: string; 5 | } 6 | -------------------------------------------------------------------------------- /benchmarks/fastify.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fastify = require('fastify')(); 4 | fastify.get('/', async (req, reply) => reply.send('Hello world')); 5 | fastify.listen(3000); 6 | -------------------------------------------------------------------------------- /integration/injector/src/circular-structure-dynamic-module/input.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class InputService {} 5 | -------------------------------------------------------------------------------- /packages/common/interfaces/hooks/before-application-shutdown.interface.ts: -------------------------------------------------------------------------------- 1 | export interface BeforeApplicationShutdown { 2 | beforeApplicationShutdown(signal?: string): any; 3 | } 4 | -------------------------------------------------------------------------------- /packages/common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/testing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateCatDto { 2 | readonly name: string; 3 | readonly age: number; 4 | readonly breed: string; 5 | } 6 | -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/cats/interfaces/cat.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Cat { 2 | readonly id: number; 3 | readonly name: string; 4 | readonly age: number; 5 | } 6 | -------------------------------------------------------------------------------- /packages/platform-ws/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/testing/interfaces/override-by-factory-options.interface.ts: -------------------------------------------------------------------------------- 1 | export interface OverrideByFactoryOptions { 2 | factory: (...args: any[]) => any; 3 | inject?: any[]; 4 | } 5 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/hooks/on-gateway-connection.interface.ts: -------------------------------------------------------------------------------- 1 | export interface OnGatewayConnection { 2 | handleConnection(client: T, ...args: any[]): any; 3 | } 4 | -------------------------------------------------------------------------------- /packages/websockets/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/microservices/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/platform-express/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/platform-fastify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/common/decorators/roles.decorator.ts: -------------------------------------------------------------------------------- 1 | import { SetMetadata } from '@nestjs/common'; 2 | 3 | export const Roles = (...roles: string[]) => SetMetadata('roles', roles); 4 | -------------------------------------------------------------------------------- /sample/10-fastify/src/common/decorators/roles.decorator.ts: -------------------------------------------------------------------------------- 1 | import { SetMetadata } from '@nestjs/common'; 2 | 3 | export const Roles = (...roles: string[]) => SetMetadata('roles', roles); 4 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/database/datamodel.graphql: -------------------------------------------------------------------------------- 1 | type Post { 2 | id: ID! @unique @id 3 | isPublished: Boolean! @default(value: false) 4 | title: String! 5 | text: String! 6 | } 7 | -------------------------------------------------------------------------------- /packages/common/enums/request-method.enum.ts: -------------------------------------------------------------------------------- 1 | export enum RequestMethod { 2 | GET = 0, 3 | POST, 4 | PUT, 5 | DELETE, 6 | PATCH, 7 | ALL, 8 | OPTIONS, 9 | HEAD, 10 | } 11 | -------------------------------------------------------------------------------- /packages/microservices/errors/net-socket-closed.exception.ts: -------------------------------------------------------------------------------- 1 | export class NetSocketClosedException extends Error { 2 | constructor() { 3 | super(`The net socket is closed.`); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/platform-socket.io/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "include": ["*.ts", "**/*.ts"] 7 | } 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # source 2 | **/*.ts 3 | *.ts 4 | 5 | # definitions 6 | !**/*.d.ts 7 | !*.d.ts 8 | 9 | # configuration 10 | package-lock.json 11 | tslint.json 12 | tsconfig.json 13 | .prettierrc -------------------------------------------------------------------------------- /benchmarks/express.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | const app = express(); 5 | 6 | app.get('/', async (req, res) => res.send('Hello world')); 7 | app.listen(3000); 8 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/client-grpc.interface.ts: -------------------------------------------------------------------------------- 1 | export interface ClientGrpc { 2 | getService(name: string): T; 3 | getClientByServiceName(name: string): T; 4 | } 5 | -------------------------------------------------------------------------------- /packages/platform-ws/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest @platform-ws 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | 8 | export * from './adapters'; 9 | -------------------------------------------------------------------------------- /sample/08-webpack/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello() { 6 | return 'Hello world!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/09-babel-example/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES6", 4 | "experimentalDecorators": true 5 | }, 6 | "exclude": [ 7 | "node_modules" 8 | ] 9 | } -------------------------------------------------------------------------------- /packages/common/interfaces/middleware/nest-middleware.interface.ts: -------------------------------------------------------------------------------- 1 | export interface NestMiddleware { 2 | use(req: TRequest, res: TResponse, next: () => void): any; 3 | } 4 | -------------------------------------------------------------------------------- /packages/microservices/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './json-socket'; 2 | export * from './kafka-logger'; 3 | export * from './kafka-parser'; 4 | export * from './kafka-round-robin-partition-assigner'; 5 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from './on-gateway-connection.interface'; 2 | export * from './on-gateway-disconnect.interface'; 3 | export * from './on-gateway-init.interface'; 4 | -------------------------------------------------------------------------------- /sample/06-mongoose/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | mongodb: 5 | image: mongo:latest 6 | environment: 7 | - MONGODB_DATABASE="test" 8 | ports: 9 | - 27017:27017 -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | mongodb: 5 | image: mongo:latest 6 | environment: 7 | - MONGODB_DATABASE="test" 8 | ports: 9 | - 27017:27017 -------------------------------------------------------------------------------- /sample/14-mongoose-base/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | mongodb: 5 | image: mongo:latest 6 | environment: 7 | - MONGODB_DATABASE="test" 8 | ports: 9 | - 27017:27017 -------------------------------------------------------------------------------- /sample/18-context/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello world!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/26-queues/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/27-scheduling/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /integration/mongoose/src/cats/schemas/cat.schema.ts: -------------------------------------------------------------------------------- 1 | import * as mongoose from 'mongoose'; 2 | 3 | export const CatSchema = new mongoose.Schema({ 4 | name: String, 5 | age: Number, 6 | breed: String, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/common/http/http.constants.ts: -------------------------------------------------------------------------------- 1 | export const AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN'; 2 | export const HTTP_MODULE_ID = 'HTTP_MODULE_ID'; 3 | export const HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS'; 4 | -------------------------------------------------------------------------------- /packages/common/interfaces/features/custom-route-param-factory.interface.ts: -------------------------------------------------------------------------------- 1 | export type CustomParamFactory = ( 2 | data: TData, 3 | input: TInput, 4 | ) => TOutput; 5 | -------------------------------------------------------------------------------- /packages/platform-socket.io/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest @platform-socket.io 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | 8 | export * from './adapters'; 9 | -------------------------------------------------------------------------------- /sample/04-grpc/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HeroModule } from './hero/hero.module'; 3 | 4 | @Module({ 5 | imports: [HeroModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/11-swagger/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsModule } from './cats/cats.module'; 3 | 4 | @Module({ 5 | imports: [CatsModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/15-mvc/views/index.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | App 7 | 8 | 9 | 10 | {{ message }} 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/18-context/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Module({ 5 | providers: [AppService], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /integration/injector/src/scoped/scoped.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Scope } from '@nestjs/common'; 2 | 3 | @Controller({ 4 | path: 'test', 5 | scope: Scope.REQUEST, 6 | }) 7 | export class ScopedController {} 8 | -------------------------------------------------------------------------------- /integration/microservices/src/kafka/dtos/business.dto.ts: -------------------------------------------------------------------------------- 1 | import { UserEntity } from '../entities/user.entity'; 2 | 3 | export class BusinessDto { 4 | name: string; 5 | phone: string; 6 | user: UserEntity; 7 | } 8 | -------------------------------------------------------------------------------- /packages/core/injector/index.ts: -------------------------------------------------------------------------------- 1 | export * from './container'; 2 | export { ContextId } from './instance-wrapper'; 3 | export * from './module-ref'; 4 | export * from './modules-container'; 5 | export * from './inquirer'; 6 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/cats/schemas/cat.schema.ts: -------------------------------------------------------------------------------- 1 | import * as mongoose from 'mongoose'; 2 | 3 | export const CatSchema = new mongoose.Schema({ 4 | name: String, 5 | age: Number, 6 | breed: String, 7 | }); 8 | -------------------------------------------------------------------------------- /sample/17-mvc-fastify/views/index.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | App 7 | 8 | 9 | 10 | {{ message }} 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/21-serializer/src/entities/role.entity.ts: -------------------------------------------------------------------------------- 1 | export class RoleEntity { 2 | id: number; 3 | name: string; 4 | 5 | constructor(partial: Partial) { 6 | Object.assign(this, partial); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/**/*.spec.ts", "src/graphql.schema.d.ts"], 5 | "exec": "ts-node -r tsconfig-paths/register src/main.ts" 6 | } 7 | -------------------------------------------------------------------------------- /scripts/prepare.sh: -------------------------------------------------------------------------------- 1 | # 1. Build fresh packages and move them to sample and integration directories 2 | npm run build &>/dev/null 3 | 4 | # 2. Start docker containers to perform integration tests 5 | npm run test:docker:up -------------------------------------------------------------------------------- /integration/hello-world/src/hello/hello.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class HelloService { 5 | greeting(): string { 6 | return 'Hello world!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /integration/hello-world/src/hello/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class UsersService { 5 | findById(id: string) { 6 | return { id }; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /integration/hello-world/src/host/host.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class HostService { 5 | greeting(): string { 6 | return 'Host Greeting!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc-advanced/proto/common/item_types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package proto_example.common.items; 3 | 4 | enum ItemType { 5 | DEFAULT = 0; 6 | SUPERIOR = 1; 7 | FLAWLESS = 2; 8 | } -------------------------------------------------------------------------------- /packages/common/cache/index.ts: -------------------------------------------------------------------------------- 1 | export { CACHE_MANAGER } from './cache.constants'; 2 | export * from './cache.module'; 3 | export * from './decorators'; 4 | export * from './interceptors'; 5 | export * from './interfaces'; 6 | -------------------------------------------------------------------------------- /packages/core/router/interfaces/resolver.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Resolver { 2 | resolve(instance: any, basePath: string): void; 3 | registerNotFoundHandler(): void; 4 | registerExceptionHandler(): void; 5 | } 6 | -------------------------------------------------------------------------------- /packages/platform-express/multer/interceptors/index.ts: -------------------------------------------------------------------------------- 1 | export * from './any-files.interceptor'; 2 | export * from './file-fields.interceptor'; 3 | export * from './file.interceptor'; 4 | export * from './files.interceptor'; 5 | -------------------------------------------------------------------------------- /packages/websockets/utils/compare-element.util.ts: -------------------------------------------------------------------------------- 1 | export function compareElementAt( 2 | prev: unknown[], 3 | curr: unknown[], 4 | index: number, 5 | ) { 6 | return prev && curr && prev[index] === curr[index]; 7 | } 8 | -------------------------------------------------------------------------------- /sample/02-gateways/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { EventsModule } from './events/events.module'; 3 | 4 | @Module({ 5 | imports: [EventsModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/03-microservices/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { MathModule } from './math/math.module'; 3 | 4 | @Module({ 5 | imports: [MathModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/09-babel-example/src/app.module.js: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsModule } from './cats/cats.module'; 3 | 4 | @Module({ 5 | imports: [CatsModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsModule } from './cats/cats.module'; 3 | 4 | @Module({ 5 | imports: [CatsModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/nodemon-debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/**/*.spec.ts"], 5 | "exec": "node --inspect-brk -r ts-node/register -r tsconfig-paths/register src/main.ts" 6 | } 7 | -------------------------------------------------------------------------------- /integration/nest-application/get-url/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | sayHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/16-gateways-ws/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { EventsModule } from './events/events.module'; 3 | 4 | @Module({ 5 | imports: [EventsModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/auth/guards/jwt-auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { AuthGuard } from '@nestjs/passport'; 3 | 4 | @Injectable() 5 | export class JwtAuthGuard extends AuthGuard('jwt') {} 6 | -------------------------------------------------------------------------------- /sample/21-serializer/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | 4 | @Module({ 5 | controllers: [AppController], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /integration/hello-world/src/host/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class UsersService { 5 | findById(id: string) { 6 | return { id, host: true }; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /integration/injector/src/scoped/transient2.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Logger, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.TRANSIENT }) 4 | export class Transient2Service { 5 | logger = new Logger(); 6 | } 7 | -------------------------------------------------------------------------------- /packages/common/interfaces/modules/nest-module.interface.ts: -------------------------------------------------------------------------------- 1 | import { MiddlewareConsumer } from '../middleware/middleware-consumer.interface'; 2 | 3 | export interface NestModule { 4 | configure(consumer: MiddlewareConsumer); 5 | } 6 | -------------------------------------------------------------------------------- /packages/common/utils/forward-ref.util.ts: -------------------------------------------------------------------------------- 1 | import { ForwardReference } from '../interfaces/modules/forward-reference.interface'; 2 | 3 | export const forwardRef = (fn: () => any): ForwardReference => ({ 4 | forwardRef: fn, 5 | }); 6 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/nest-gateway.interface.ts: -------------------------------------------------------------------------------- 1 | export interface NestGateway { 2 | afterInit?: (server: any) => void; 3 | handleConnection?: (...args: any[]) => void; 4 | handleDisconnect?: (client: any) => void; 5 | } 6 | -------------------------------------------------------------------------------- /sample/02-gateways/src/events/events.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { EventsGateway } from './events.gateway'; 3 | 4 | @Module({ 5 | providers: [EventsGateway], 6 | }) 7 | export class EventsModule {} 8 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/auth/guards/local-auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { AuthGuard } from '@nestjs/passport'; 3 | 4 | @Injectable() 5 | export class LocalAuthGuard extends AuthGuard('local') {} 6 | -------------------------------------------------------------------------------- /sample/27-scheduling/src/tasks/tasks.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { TasksService } from './tasks.service'; 3 | 4 | @Module({ 5 | providers: [TasksService], 6 | }) 7 | export class TasksModule {} 8 | -------------------------------------------------------------------------------- /integration/injector/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ExportsModule } from './exports/exports.module'; 3 | 4 | @Module({ 5 | imports: [ExportsModule], 6 | }) 7 | export class ApplicationModule {} 8 | -------------------------------------------------------------------------------- /integration/injector/src/inject/inject.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { InjectService } from './inject.service'; 3 | 4 | @Module({ 5 | providers: [InjectService], 6 | }) 7 | export class InjectModule {} 8 | -------------------------------------------------------------------------------- /integration/mongoose/src/cats/interfaces/cat.interface.ts: -------------------------------------------------------------------------------- 1 | import { Document } from 'mongoose'; 2 | 3 | export interface Cat extends Document { 4 | readonly name: string; 5 | readonly age: number; 6 | readonly breed: string; 7 | } 8 | -------------------------------------------------------------------------------- /packages/microservices/client/constants.ts: -------------------------------------------------------------------------------- 1 | export const ECONNREFUSED = 'ECONNREFUSED'; 2 | export const CONN_ERR = 'CONN_ERR'; 3 | export const GRPC_CANCELLED = 'Cancelled'; 4 | export const RABBITMQ_REPLY_QUEUE = 'amq.rabbitmq.reply-to'; 5 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/cats/interfaces/cat.interface.ts: -------------------------------------------------------------------------------- 1 | import { Document } from 'mongoose'; 2 | 3 | export interface Cat extends Document { 4 | readonly name: string; 5 | readonly age: number; 6 | readonly breed: string; 7 | } 8 | -------------------------------------------------------------------------------- /sample/16-gateways-ws/src/events/events.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { EventsGateway } from './events.gateway'; 3 | 4 | @Module({ 5 | providers: [EventsGateway], 6 | }) 7 | export class EventsModule {} 8 | -------------------------------------------------------------------------------- /sample/24-serve-static/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | 3 | @Controller() 4 | export class AppController { 5 | @Get() 6 | getHello() { 7 | return 'Hello, world!'; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /integration/injector/src/exports/exports.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ExportsService } from './exports.service'; 3 | 4 | @Module({ 5 | exports: [ExportsService], 6 | }) 7 | export class ExportsModule {} 8 | -------------------------------------------------------------------------------- /integration/websockets/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ApplicationGateway } from './app.gateway'; 3 | 4 | @Module({ 5 | providers: [ApplicationGateway], 6 | }) 7 | export class ApplicationModule {} 8 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/runtime.exception.ts: -------------------------------------------------------------------------------- 1 | export class RuntimeException extends Error { 2 | constructor(message = ``) { 3 | super(message); 4 | } 5 | 6 | public what() { 7 | return this.message; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/core/helpers/optional-require.ts: -------------------------------------------------------------------------------- 1 | export function optionalRequire(packageName: string, loaderFn?: Function) { 2 | try { 3 | return loaderFn ? loaderFn() : require(packageName); 4 | } catch (e) { 5 | return {}; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /integration/injector/src/defaults/defaults.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { DefaultsService } from './defaults.service'; 3 | 4 | @Module({ 5 | providers: [DefaultsService], 6 | }) 7 | export class DefaultsModule {} 8 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc-advanced/proto/common/shipment_types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package proto_example.common.shipments; 3 | 4 | message ShipmentType { 5 | string from = 1; 6 | string to = 2; 7 | string carrier = 3; 8 | } -------------------------------------------------------------------------------- /sample/01-cats-app/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # tests 13 | /test 14 | /coverage 15 | /.nyc_output 16 | 17 | # dist 18 | /dist -------------------------------------------------------------------------------- /tools/gulp/config.ts: -------------------------------------------------------------------------------- 1 | import { getDirs } from './util/task-helpers'; 2 | 3 | // All paths are related to the base dir 4 | export const source = 'packages'; 5 | export const samplePath = 'sample'; 6 | 7 | export const packagePaths = getDirs(source); 8 | -------------------------------------------------------------------------------- /packages/common/interfaces/microservices/nest-microservice-options.interface.ts: -------------------------------------------------------------------------------- 1 | import { NestApplicationContextOptions } from '../nest-application-context-options.interface'; 2 | 3 | export type NestMicroserviceOptions = NestApplicationContextOptions; 4 | -------------------------------------------------------------------------------- /packages/core/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from './on-app-bootstrap.hook'; 2 | export * from './on-app-shutdown.hook'; 3 | export * from './on-module-destroy.hook'; 4 | export * from './on-module-init.hook'; 5 | export * from './before-app-shutdown.hook'; 6 | -------------------------------------------------------------------------------- /packages/microservices/ctx-host/index.ts: -------------------------------------------------------------------------------- 1 | export * from './kafka.context'; 2 | export * from './mqtt.context'; 3 | export * from './nats.context'; 4 | export * from './redis.context'; 5 | export * from './rmq.context'; 6 | export * from './tcp.context'; 7 | -------------------------------------------------------------------------------- /packages/microservices/serializers/identity.serializer.ts: -------------------------------------------------------------------------------- 1 | import { Serializer } from '../interfaces/serializer.interface'; 2 | 3 | export class IdentitySerializer implements Serializer { 4 | serialize(value: any) { 5 | return value; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/platform-fastify/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest @platform-express 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | 8 | export * from './adapters'; 9 | export * from './interfaces'; 10 | -------------------------------------------------------------------------------- /packages/common/enums/route-paramtypes.enum.ts: -------------------------------------------------------------------------------- 1 | export enum RouteParamtypes { 2 | REQUEST, 3 | RESPONSE, 4 | NEXT, 5 | BODY, 6 | QUERY, 7 | PARAM, 8 | HEADERS, 9 | SESSION, 10 | FILE, 11 | FILES, 12 | HOST, 13 | IP, 14 | } 15 | -------------------------------------------------------------------------------- /packages/common/interfaces/middleware/index.ts: -------------------------------------------------------------------------------- 1 | export * from './middleware-config-proxy.interface'; 2 | export * from './middleware-configuration.interface'; 3 | export * from './middleware-consumer.interface'; 4 | export * from './nest-middleware.interface'; 5 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-json-format.exception.ts: -------------------------------------------------------------------------------- 1 | export class InvalidJSONFormatException extends Error { 2 | constructor(err: Error, data: string) { 3 | super(`Could not parse JSON: ${err.message}\nRequest data: ${data}`); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | import { Min } from 'class-validator'; 2 | import { CreateCatInput } from '../../graphql.schema'; 3 | 4 | export class CreateCatDto extends CreateCatInput { 5 | @Min(1) 6 | age: number; 7 | } 8 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/users/users.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { UsersService } from './users.service'; 3 | 4 | @Module({ 5 | providers: [UsersService], 6 | exports: [UsersService], 7 | }) 8 | export class UsersModule {} 9 | -------------------------------------------------------------------------------- /sample/24-serve-static/client/index.html: -------------------------------------------------------------------------------- 1 | 2 |

Static website

3 | 8 | -------------------------------------------------------------------------------- /integration/scopes/src/hello/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /integration/scopes/src/msvc/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /packages/common/pipes/index.ts: -------------------------------------------------------------------------------- 1 | export * from './default-value.pipe'; 2 | export * from './parse-array.pipe'; 3 | export * from './parse-bool.pipe'; 4 | export * from './parse-int.pipe'; 5 | export * from './parse-uuid.pipe'; 6 | export * from './validation.pipe'; 7 | -------------------------------------------------------------------------------- /packages/core/helpers/interfaces/params-metadata.interface.ts: -------------------------------------------------------------------------------- 1 | import { ParamData } from '@nestjs/common'; 2 | 3 | export type ParamsMetadata = Record; 4 | export interface ParamMetadata { 5 | index: number; 6 | data?: ParamData; 7 | } 8 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './gateway-metadata.interface'; 2 | export * from './hooks'; 3 | export * from './socket-events-host.interface'; 4 | export * from './web-socket-server.interface'; 5 | export * from './ws-response.interface'; 6 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["config:base"], 3 | "semanticCommits": true, 4 | "packageRules": [ 5 | { 6 | "depTypeList": ["devDependencies"], 7 | "automerge": true 8 | } 9 | ], 10 | "schedule": ["every weekday"] 11 | } 12 | -------------------------------------------------------------------------------- /integration/hello-world/src/hello/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /integration/hello-world/src/host/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /integration/scopes/src/transient/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /packages/microservices/deserializers/identity.deserializer.ts: -------------------------------------------------------------------------------- 1 | import { Deserializer } from '../interfaces/deserializer.interface'; 2 | 3 | export class IdentityDeserializer implements Deserializer { 4 | deserialize(value: any) { 5 | return value; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/custom-transport-strategy.interface.ts: -------------------------------------------------------------------------------- 1 | import { Transport } from '../enums'; 2 | 3 | export interface CustomTransportStrategy { 4 | readonly transportId?: Transport; 5 | listen(callback: () => void): any; 6 | close(): any; 7 | } 8 | -------------------------------------------------------------------------------- /sample/07-sequelize/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | mysql: 5 | image: mysql:5 6 | restart: always 7 | environment: 8 | MYSQL_ROOT_PASSWORD: root 9 | MYSQL_DATABASE: test 10 | ports: 11 | - "3306:3306" 12 | -------------------------------------------------------------------------------- /sample/15-mvc/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Render } from '@nestjs/common'; 2 | 3 | @Controller() 4 | export class AppController { 5 | @Get() 6 | @Render('index') 7 | root() { 8 | return { message: 'Hello world!' }; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sample/15-mvc/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | 4 | @Module({ 5 | imports: [], 6 | controllers: [AppController], 7 | providers: [], 8 | }) 9 | export class AppModule {} 10 | -------------------------------------------------------------------------------- /scripts/run-integration.sh: -------------------------------------------------------------------------------- 1 | # 1. Build fresh packages and move them integration dit 2 | npm run build &>/dev/null 3 | 4 | # 2. Start docker containers to perform integration tests 5 | npm run test:docker:up 6 | 7 | # 3. Run integration tests 8 | npm run test:integration -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/config.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ConfigService } from './config.service'; 3 | 4 | @Module({ 5 | providers: [ConfigService], 6 | exports: [ConfigService], 7 | }) 8 | export class ConfigModule {} 9 | -------------------------------------------------------------------------------- /integration/injector/src/inject/inject.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { CoreService } from './core.service'; 3 | 4 | @Injectable() 5 | export class InjectService { 6 | constructor(private readonly coreService: CoreService) {} 7 | } 8 | -------------------------------------------------------------------------------- /integration/scopes/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HelloModule } from './hello/hello.module'; 3 | 4 | @Module({ 5 | imports: [HelloModule.forRoot({ provide: 'META', useValue: true })], 6 | }) 7 | export class ApplicationModule {} 8 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-hello/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /integration/websockets/src/ack.gateway.ts: -------------------------------------------------------------------------------- 1 | import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets'; 2 | 3 | @WebSocketGateway(8080) 4 | export class AckGateway { 5 | @SubscribeMessage('push') 6 | onPush() { 7 | return 'pong'; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/microservices/errors/corrupted-packet-length.exception.ts: -------------------------------------------------------------------------------- 1 | export class CorruptedPacketLengthException extends Error { 2 | constructor(rawContentLength: string) { 3 | super(`Corrupted length value "${rawContentLength}" supplied in a packet`); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sample/05-sql-typeorm/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | mysql: 5 | image: mysql:5 6 | restart: always 7 | environment: 8 | MYSQL_ROOT_PASSWORD: root 9 | MYSQL_DATABASE: test 10 | ports: 11 | - "3306:3306" 12 | -------------------------------------------------------------------------------- /sample/20-cache/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { CacheModule, Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | 4 | @Module({ 5 | imports: [CacheModule.register()], 6 | controllers: [AppController], 7 | }) 8 | export class AppModule {} 9 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/src/prisma/prisma.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { PrismaService } from './prisma.service'; 3 | 4 | @Module({ 5 | providers: [PrismaService], 6 | exports: [PrismaService], 7 | }) 8 | export class PrismaModule {} 9 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-transient/dto/test.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; 2 | 3 | export class TestDto { 4 | @IsString() 5 | @IsNotEmpty() 6 | string: string; 7 | 8 | @IsNumber() 9 | number: number; 10 | } 11 | -------------------------------------------------------------------------------- /integration/typeorm/ormconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "mysql", 3 | "host": "localhost", 4 | "port": 3306, 5 | "username": "root", 6 | "password": "root", 7 | "database": "test", 8 | "entities": ["src/**/**.entity{.ts,.js}"], 9 | "synchronize": true 10 | } 11 | -------------------------------------------------------------------------------- /packages/common/cache/cache.constants.ts: -------------------------------------------------------------------------------- 1 | export const CACHE_MANAGER = 'CACHE_MANAGER'; 2 | export const CACHE_MODULE_OPTIONS = 'CACHE_MODULE_OPTIONS'; 3 | export const CACHE_KEY_METADATA = 'cache_module:cache_key'; 4 | export const CACHE_TTL_METADATA = 'cache_module:cache_ttl'; 5 | -------------------------------------------------------------------------------- /packages/core/injector/constants.ts: -------------------------------------------------------------------------------- 1 | import { ContextId } from './instance-wrapper'; 2 | 3 | export const CONTROLLER_ID_KEY = 'CONTROLLER_ID'; 4 | 5 | const STATIC_CONTEXT_ID = 1; 6 | export const STATIC_CONTEXT: ContextId = Object.freeze({ 7 | id: STATIC_CONTEXT_ID, 8 | }); 9 | -------------------------------------------------------------------------------- /packages/websockets/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './connected-socket.decorator'; 2 | export * from './gateway-server.decorator'; 3 | export * from './message-body.decorator'; 4 | export * from './socket-gateway.decorator'; 5 | export * from './subscribe-message.decorator'; 6 | -------------------------------------------------------------------------------- /sample/10-fastify/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsModule } from './cats/cats.module'; 3 | import { CoreModule } from './core/core.module'; 4 | 5 | @Module({ 6 | imports: [CatsModule, CoreModule], 7 | }) 8 | export class AppModule {} 9 | -------------------------------------------------------------------------------- /sample/17-mvc-fastify/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | 4 | @Module({ 5 | imports: [], 6 | controllers: [AppController], 7 | providers: [], 8 | }) 9 | export class AppModule {} 10 | -------------------------------------------------------------------------------- /integration/mongoose/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { ApplicationModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(ApplicationModule); 6 | await app.listen(3001); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /integration/scopes/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { ApplicationModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(ApplicationModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /integration/scopes/src/request-chain/helper/helper.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HelperService } from './helper.service'; 3 | 4 | @Module({ 5 | providers: [HelperService], 6 | exports: [HelperService], 7 | }) 8 | export class HelperModule {} 9 | -------------------------------------------------------------------------------- /integration/typeorm/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { ApplicationModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(ApplicationModule); 6 | await app.listen(3001); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /packages/platform-express/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest @platform-express 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | 8 | export * from './adapters'; 9 | export * from './interfaces'; 10 | export * from './multer'; 11 | -------------------------------------------------------------------------------- /packages/websockets/interfaces/socket-events-host.interface.ts: -------------------------------------------------------------------------------- 1 | import { ReplaySubject, Subject } from 'rxjs'; 2 | 3 | export interface SocketEventsHost { 4 | server: T; 5 | init: ReplaySubject; 6 | connection: Subject; 7 | disconnect: Subject; 8 | } 9 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsModule } from './cats/cats.module'; 3 | import { CoreModule } from './core/core.module'; 4 | 5 | @Module({ 6 | imports: [CoreModule, CatsModule], 7 | }) 8 | export class AppModule {} 9 | -------------------------------------------------------------------------------- /sample/04-grpc/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/08-webpack/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/10-fastify/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/11-swagger/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/15-mvc/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/17-mvc-fastify/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Get, Controller, Render } from '@nestjs/common'; 2 | 3 | @Controller() 4 | export class AppController { 5 | @Get() 6 | @Render('index.hbs') 7 | root() { 8 | return { message: 'Hello world!' }; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sample/18-context/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/20-cache/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /integration/microservices/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { ApplicationModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(ApplicationModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /sample/02-gateways/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/05-sql-typeorm/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/06-mongoose/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/07-sequelize/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/10-fastify/README.md: -------------------------------------------------------------------------------- 1 | ### Fastify sample 2 | 3 | Note that if you are running the Nest app on a remote machine, you may need to change the listen address, as per [these instructions](https://docs.nestjs.com/techniques/performance#adapter): 4 | 5 | `await app.listen(3000, '0.0.0.0')` -------------------------------------------------------------------------------- /sample/16-gateways-ws/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/17-mvc-fastify/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/21-serializer/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/24-serve-static/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /packages/microservices/decorators/ctx.decorator.ts: -------------------------------------------------------------------------------- 1 | import { RpcParamtype } from '../enums/rpc-paramtype.enum'; 2 | import { createRpcParamDecorator } from '../utils/param.utils'; 3 | 4 | export const Ctx: () => ParameterDecorator = createRpcParamDecorator( 5 | RpcParamtype.CONTEXT, 6 | ); 7 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/message-handler.interface.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | 3 | export interface MessageHandler { 4 | (data: TInput, ctx?: TContext): Promise>; 5 | isEventHandler?: boolean; 6 | } 7 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/pattern.interface.ts: -------------------------------------------------------------------------------- 1 | export type MsFundamentalPattern = string | number; 2 | 3 | export interface MsObjectPattern { 4 | [key: string]: MsFundamentalPattern | MsObjectPattern; 5 | } 6 | 7 | export type MsPattern = MsObjectPattern | MsFundamentalPattern; 8 | -------------------------------------------------------------------------------- /sample/03-microservices/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/09-babel-example/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/14-mongoose-base/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/17-mvc-fastify/README.md: -------------------------------------------------------------------------------- 1 | ### Fastify MVC sample 2 | 3 | Note that if you are running the Nest app on a remote machine, you may need to change the listen address, as per [these instructions](https://docs.nestjs.com/techniques/performance#adapter): 4 | 5 | `await app.listen(3000, '0.0.0.0')` -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { ApplicationModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(ApplicationModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /integration/hello-world/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HelloModule } from './hello/hello.module'; 3 | import { HostModule } from './host/host.module'; 4 | 5 | @Module({ 6 | imports: [HelloModule, HostModule], 7 | }) 8 | export class ApplicationModule {} 9 | -------------------------------------------------------------------------------- /packages/common/interfaces/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from './before-application-shutdown.interface'; 2 | export * from './on-application-bootstrap.interface'; 3 | export * from './on-application-shutdown.interface'; 4 | export * from './on-destroy.interface'; 5 | export * from './on-init.interface'; 6 | -------------------------------------------------------------------------------- /packages/microservices/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './client.decorator'; 2 | export * from './ctx.decorator'; 3 | export * from './event-pattern.decorator'; 4 | export * from './grpc-service.decorator'; 5 | export * from './message-pattern.decorator'; 6 | export * from './payload.decorator'; 7 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/database/database.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { databaseProviders } from './database.providers'; 3 | 4 | @Module({ 5 | providers: [...databaseProviders], 6 | exports: [...databaseProviders], 7 | }) 8 | export class DatabaseModule {} 9 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.awcache 7 | /.vscode 8 | 9 | # misc 10 | npm-debug.log 11 | 12 | # example 13 | /quick-start 14 | 15 | # tests 16 | /test 17 | /coverage 18 | /.nyc_output 19 | 20 | # dist 21 | /dist -------------------------------------------------------------------------------- /integration/injector/src/scoped/scoped.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | import { REQUEST } from '@nestjs/core'; 3 | 4 | @Injectable({ scope: Scope.REQUEST }) 5 | export class ScopedService { 6 | constructor(@Inject(REQUEST) public readonly request) {} 7 | } 8 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsInt, IsString } from 'class-validator'; 2 | 3 | export class CreateCatDto { 4 | @IsString() 5 | readonly name: string; 6 | 7 | @IsInt() 8 | readonly age: number; 9 | 10 | @IsString() 11 | readonly breed: string; 12 | } 13 | -------------------------------------------------------------------------------- /sample/10-fastify/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsInt, IsString } from 'class-validator'; 2 | 3 | export class CreateCatDto { 4 | @IsString() 5 | readonly name: string; 6 | 7 | @IsInt() 8 | readonly age: number; 9 | 10 | @IsString() 11 | readonly breed: string; 12 | } 13 | -------------------------------------------------------------------------------- /sample/11-swagger/src/cats/dto/create-cat.dto.ts: -------------------------------------------------------------------------------- 1 | import { IsInt, IsString } from 'class-validator'; 2 | 3 | export class CreateCatDto { 4 | @IsString() 5 | readonly name: string; 6 | 7 | @IsInt() 8 | readonly age: number; 9 | 10 | @IsString() 11 | readonly breed: string; 12 | } 13 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/cats/cats.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsResolvers } from './cats.resolvers'; 3 | import { CatsService } from './cats.service'; 4 | 5 | @Module({ 6 | providers: [CatsService, CatsResolvers], 7 | }) 8 | export class CatsModule {} 9 | -------------------------------------------------------------------------------- /packages/microservices/server/index.ts: -------------------------------------------------------------------------------- 1 | export * from './server'; 2 | export * from './server-grpc'; 3 | export * from './server-kafka'; 4 | export * from './server-mqtt'; 5 | export * from './server-nats'; 6 | export * from './server-redis'; 7 | export * from './server-rmq'; 8 | export * from './server-tcp'; 9 | -------------------------------------------------------------------------------- /packages/websockets/decorators/connected-socket.decorator.ts: -------------------------------------------------------------------------------- 1 | import { WsParamtype } from '../enums/ws-paramtype.enum'; 2 | import { createWsParamDecorator } from '../utils/param.utils'; 3 | 4 | export const ConnectedSocket: () => ParameterDecorator = createWsParamDecorator( 5 | WsParamtype.SOCKET, 6 | ); 7 | -------------------------------------------------------------------------------- /sample/09-babel-example/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"], 3 | "plugins": [ 4 | ["@babel/plugin-proposal-decorators", { "legacy": true }], 5 | [ 6 | "@babel/plugin-transform-runtime", 7 | { 8 | "regenerator": true 9 | } 10 | ] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /benchmarks/nest/main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AACD,SAAS,EAAE,CAAC"} -------------------------------------------------------------------------------- /integration/injector/src/circular/circular.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CircularService } from './circular.service'; 3 | import { InputService } from './input.service'; 4 | 5 | @Module({ 6 | providers: [CircularService, InputService], 7 | }) 8 | export class CircularModule {} 9 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc/math2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package math2; 4 | 5 | service Math2 { 6 | rpc Sum2 (RequestSum) returns (SumResult) {} 7 | } 8 | 9 | message SumResult { 10 | int32 result = 1; 11 | } 12 | 13 | message RequestSum { 14 | repeated int32 data = 1; 15 | } 16 | -------------------------------------------------------------------------------- /packages/testing/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest @testing 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | 8 | export * from './interfaces'; 9 | export * from './test'; 10 | export * from './testing-module'; 11 | export * from './testing-module.builder'; 12 | -------------------------------------------------------------------------------- /integration/injector/src/scoped/transient.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Scope } from '@nestjs/common'; 2 | import { Transient2Service } from './transient2.service'; 3 | 4 | @Injectable({ scope: Scope.TRANSIENT }) 5 | export class TransientService { 6 | constructor(public readonly svc: Transient2Service) {} 7 | } 8 | -------------------------------------------------------------------------------- /integration/injector/src/scoped/transient3.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Scope } from '@nestjs/common'; 2 | import { TransientService } from './transient.service'; 3 | 4 | @Injectable({ scope: Scope.TRANSIENT }) 5 | export class Transient3Service { 6 | constructor(public readonly svc: TransientService) {} 7 | } 8 | -------------------------------------------------------------------------------- /packages/common/interfaces/modules/introspection-result.interface.ts: -------------------------------------------------------------------------------- 1 | import { Scope } from '../scope-options.interface'; 2 | 3 | /** 4 | * @publicApi 5 | */ 6 | export interface IntrospectionResult { 7 | /** 8 | * Enum defining lifetime of host class or factory. 9 | */ 10 | scope: Scope; 11 | } 12 | -------------------------------------------------------------------------------- /packages/microservices/decorators/grpc-service.decorator.ts: -------------------------------------------------------------------------------- 1 | import { Controller } from '@nestjs/common'; 2 | 3 | /** 4 | * Defines the GrpcService. The service can inject dependencies through constructor. 5 | * Those dependencies have to belong to the same module. 6 | */ 7 | export const GrpcService = Controller; 8 | -------------------------------------------------------------------------------- /integration/scopes/src/resolve-scoped/logger.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | import { LOGGER_PROVIDER } from './logger.provider'; 3 | 4 | @Injectable({ scope: Scope.TRANSIENT }) 5 | export class LoggerService { 6 | constructor(@Inject(LOGGER_PROVIDER) public logger) {} 7 | } 8 | -------------------------------------------------------------------------------- /integration/scopes/src/resolve-scoped/request-logger.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Scope } from '@nestjs/common'; 2 | import { LoggerService } from './logger.service'; 3 | 4 | @Injectable({ scope: Scope.REQUEST }) 5 | export class RequestLoggerService { 6 | constructor(public loggerService: LoggerService) {} 7 | } 8 | -------------------------------------------------------------------------------- /integration/typeorm/src/app-async.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { DatabaseModule } from './database.module'; 3 | import { PhotoModule } from './photo/photo.module'; 4 | 5 | @Module({ 6 | imports: [DatabaseModule.forRoot(), PhotoModule], 7 | }) 8 | export class AsyncApplicationModule {} 9 | -------------------------------------------------------------------------------- /packages/common/interfaces/exceptions/exception-filter-metadata.interface.ts: -------------------------------------------------------------------------------- 1 | import { ExceptionFilter } from './exception-filter.interface'; 2 | import { Type } from '../type.interface'; 3 | 4 | export interface ExceptionFilterMetadata { 5 | func: ExceptionFilter['catch']; 6 | exceptionMetatypes: Type[]; 7 | } 8 | -------------------------------------------------------------------------------- /packages/common/interfaces/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './exception-filter-metadata.interface'; 2 | export * from './exception-filter.interface'; 3 | export * from './rpc-exception-filter-metadata.interface'; 4 | export * from './rpc-exception-filter.interface'; 5 | export * from './ws-exception-filter.interface'; 6 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-grpc-package.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidGrpcPackageException extends RuntimeException { 4 | constructor() { 5 | super('The invalid gRPC package (package not found)'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-grpc-service.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidGrpcServiceException extends RuntimeException { 4 | constructor() { 5 | super(`The invalid gRPC service (service not found)`); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-message.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidMessageException extends RuntimeException { 4 | constructor() { 5 | super(`The invalid data or message pattern (undefined/null)`); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/websockets/context/ws-metadata-constants.ts: -------------------------------------------------------------------------------- 1 | import { WsParamtype } from '../enums/ws-paramtype.enum'; 2 | 3 | export const DEFAULT_CALLBACK_METADATA = { 4 | [`${WsParamtype.PAYLOAD}:1`]: { index: 1, data: undefined, pipes: [] }, 5 | [`${WsParamtype.SOCKET}:0`]: { index: 0, data: undefined, pipes: [] }, 6 | }; 7 | -------------------------------------------------------------------------------- /sample/10-fastify/src/cats/cats.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsController } from './cats.controller'; 3 | import { CatsService } from './cats.service'; 4 | 5 | @Module({ 6 | controllers: [CatsController], 7 | providers: [CatsService], 8 | }) 9 | export class CatsModule {} 10 | -------------------------------------------------------------------------------- /sample/11-swagger/src/cats/cats.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsController } from './cats.controller'; 3 | import { CatsService } from './cats.service'; 4 | 5 | @Module({ 6 | controllers: [CatsController], 7 | providers: [CatsService], 8 | }) 9 | export class CatsModule {} 10 | -------------------------------------------------------------------------------- /benchmarks/nest/app.module.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AAMjD,IAAa,SAAS,GAAtB,MAAa,SAAS;CAAG,CAAA;AAAZ,SAAS;IAJrB,eAAM,CAAC;QACN,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,CAAC,8BAAa,CAAC;KAC7B,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"} -------------------------------------------------------------------------------- /packages/common/interfaces/modules/index.ts: -------------------------------------------------------------------------------- 1 | export * from './dynamic-module.interface'; 2 | export * from './forward-reference.interface'; 3 | export * from './introspection-result.interface'; 4 | export * from './module-metadata.interface'; 5 | export * from './nest-module.interface'; 6 | export * from './provider.interface'; 7 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/cats/cats.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsController } from './cats.controller'; 3 | import { CatsService } from './cats.service'; 4 | 5 | @Module({ 6 | controllers: [CatsController], 7 | providers: [CatsService], 8 | }) 9 | export class CatsModule {} 10 | -------------------------------------------------------------------------------- /integration/nest-application/get-url/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | @Module({ 6 | controllers: [AppController], 7 | providers: [AppService], 8 | }) 9 | export class AppModule {} 10 | -------------------------------------------------------------------------------- /integration/scopes/src/hello/hello.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class HelloService { 5 | constructor(@Inject('META') private readonly meta) {} 6 | 7 | greeting(): string { 8 | return 'Hello world!'; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /integration/scopes/src/msvc/hello.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class HelloService { 5 | constructor(@Inject('META') private readonly meta) {} 6 | 7 | greeting(): string { 8 | return 'Hello world!'; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-proto-definition.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidProtoDefinitionException extends RuntimeException { 4 | constructor() { 5 | super('The invalid .proto definition (file not found)'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/common/middleware/logger.middleware.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, NestMiddleware } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class LoggerMiddleware implements NestMiddleware { 5 | use(req: any, res: any, next: () => void) { 6 | console.log(`Request...`); 7 | next(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sample/07-sequelize/src/users/user.model.ts: -------------------------------------------------------------------------------- 1 | import { Column, Model, Table } from 'sequelize-typescript'; 2 | 3 | @Table 4 | export class User extends Model { 5 | @Column 6 | firstName: string; 7 | 8 | @Column 9 | lastName: string; 10 | 11 | @Column({ defaultValue: true }) 12 | isActive: boolean; 13 | } 14 | -------------------------------------------------------------------------------- /sample/08-webpack/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | @Module({ 6 | imports: [], 7 | controllers: [AppController], 8 | providers: [AppService], 9 | }) 10 | export class AppModule {} 11 | -------------------------------------------------------------------------------- /sample/09-babel-example/src/cats/cats.module.js: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsController } from './cats.controller'; 3 | import { CatsService } from './cats.service'; 4 | 5 | @Module({ 6 | controllers: [CatsController], 7 | providers: [CatsService], 8 | }) 9 | export class CatsModule {} 10 | -------------------------------------------------------------------------------- /sample/10-fastify/src/common/middleware/logger.middleware.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, NestMiddleware } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class LoggerMiddleware implements NestMiddleware { 5 | use(req: any, res: any, next: () => void) { 6 | console.log(`Request...`); 7 | next(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/database/database.providers.ts: -------------------------------------------------------------------------------- 1 | import * as mongoose from 'mongoose'; 2 | 3 | export const databaseProviders = [ 4 | { 5 | provide: 'DATABASE_CONNECTION', 6 | useFactory: async (): Promise => 7 | await mongoose.connect('mongodb://localhost/nest'), 8 | }, 9 | ]; 10 | -------------------------------------------------------------------------------- /.eslintrc.spec.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('./.eslintrc'); 2 | 3 | module.exports = { 4 | ...baseConfig, 5 | parserOptions: { 6 | project: 'tsconfig.spec.json', 7 | sourceType: 'module', 8 | }, 9 | rules: { 10 | ...baseConfig.rules, 11 | '@typescript-eslint/no-empty-function': 'off', 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /integration/injector/src/circular-properties/circular.service.ts: -------------------------------------------------------------------------------- 1 | import { forwardRef, Inject, Injectable } from '@nestjs/common'; 2 | import { InputService } from './input.service'; 3 | 4 | @Injectable() 5 | export class CircularService { 6 | @Inject(forwardRef(() => InputService)) 7 | public readonly service: InputService; 8 | } 9 | -------------------------------------------------------------------------------- /integration/scopes/src/transient/hello.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class HelloService { 5 | constructor(@Inject('META') private readonly meta) {} 6 | 7 | greeting(): string { 8 | return 'Hello world!'; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /integration/websockets/src/server.gateway.ts: -------------------------------------------------------------------------------- 1 | import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets'; 2 | 3 | @WebSocketGateway() 4 | export class ServerGateway { 5 | @SubscribeMessage('push') 6 | onPush(client, data) { 7 | return { 8 | event: 'pop', 9 | data, 10 | }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/common/interfaces/exceptions/rpc-exception-filter-metadata.interface.ts: -------------------------------------------------------------------------------- 1 | import { RpcExceptionFilter } from './rpc-exception-filter.interface'; 2 | import { Type } from '../type.interface'; 3 | 4 | export interface RpcExceptionFilterMetadata { 5 | func: RpcExceptionFilter['catch']; 6 | exceptionMetatypes: Type[]; 7 | } 8 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/invalid-class.exception.ts: -------------------------------------------------------------------------------- 1 | import { INVALID_CLASS_MESSAGE } from '../messages'; 2 | import { RuntimeException } from './runtime.exception'; 3 | 4 | export class InvalidClassException extends RuntimeException { 5 | constructor(value: any) { 6 | super(INVALID_CLASS_MESSAGE`${value}`); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/unknown-request-mapping.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | import { UNKNOWN_REQUEST_MAPPING } from '../messages'; 3 | 4 | export class UnknownRequestMappingException extends RuntimeException { 5 | constructor() { 6 | super(UNKNOWN_REQUEST_MAPPING); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/09-babel-example/src/cats/cats.service.js: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class CatsService { 5 | constructor() { 6 | this.cats = []; 7 | } 8 | 9 | create(cat) { 10 | this.cats.push(cat); 11 | } 12 | 13 | findAll() { 14 | return this.cats; 15 | } 16 | } -------------------------------------------------------------------------------- /benchmarks/nest/app.controller.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../src/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAiD;AAGjD,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,IAAI;QACF,OAAO,cAAc,CAAA;IACvB,CAAC;CACF,CAAA;AAHC;IADC,YAAG,EAAE;;;;yCAGL;AAJU,aAAa;IADzB,mBAAU,EAAE;GACA,aAAa,CAKzB;AALY,sCAAa"} -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/cats/cats.types.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | getCats: [Cat] 3 | cat(id: ID!): Cat 4 | } 5 | 6 | type Mutation { 7 | createCat(name: String): Cat 8 | } 9 | 10 | type Subscription { 11 | catCreated: Cat 12 | } 13 | 14 | type Cat { 15 | id: Int 16 | name: String 17 | age: Int 18 | } 19 | -------------------------------------------------------------------------------- /integration/injector/src/circular-properties/input.service.ts: -------------------------------------------------------------------------------- 1 | import { forwardRef, Inject, Injectable } from '@nestjs/common'; 2 | import { CircularService } from './circular.service'; 3 | 4 | @Injectable() 5 | export class InputService { 6 | @Inject(forwardRef(() => CircularService)) 7 | public readonly service: CircularService; 8 | } 9 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/invalid-exception-filter.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | import { INVALID_EXCEPTION_FILTER } from '../messages'; 3 | 4 | export class InvalidExceptionFilterException extends RuntimeException { 5 | constructor() { 6 | super(INVALID_EXCEPTION_FILTER); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/src/posts/posts.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { PrismaModule } from './../prisma/prisma.module'; 3 | import { PostsResolver } from './posts.resolver'; 4 | 5 | @Module({ 6 | providers: [PostsResolver], 7 | imports: [PrismaModule], 8 | }) 9 | export class PostsModule {} 10 | -------------------------------------------------------------------------------- /integration/scopes/src/resolve-scoped/logger.provider.ts: -------------------------------------------------------------------------------- 1 | import { FactoryProvider } from '@nestjs/common/interfaces'; 2 | 3 | export const LOGGER_PROVIDER = 'LOGGER_PROVIDER'; 4 | export const loggerProvider: FactoryProvider = { 5 | provide: LOGGER_PROVIDER, 6 | useFactory: () => { 7 | return { logger: true }; 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /packages/common/interfaces/hooks/on-init.interface.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface defining method called once the host module has been initialized. 3 | * 4 | * @see [Lifecycle Events](https://docs.nestjs.com/fundamentals/lifecycle-events) 5 | * 6 | * @publicApi 7 | */ 8 | export interface OnModuleInit { 9 | onModuleInit(): any; 10 | } 11 | -------------------------------------------------------------------------------- /packages/core/test/helpers/context-id-factory.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { createContextId } from '../../helpers/context-id-factory'; 3 | 4 | describe('createContextId', () => { 5 | it('should return an object with random "id" property', () => { 6 | expect(createContextId()).to.have.property('id'); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/websockets/errors/invalid-socket-port.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidSocketPortException extends RuntimeException { 4 | constructor(port: number | string, type: any) { 5 | super(`Invalid port (${port}) in gateway ${type}`); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /sample/02-gateways/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/06-mongoose/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/07-sequelize/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/20-cache/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CacheInterceptor, 3 | Controller, 4 | Get, 5 | UseInterceptors, 6 | } from '@nestjs/common'; 7 | 8 | @Controller() 9 | @UseInterceptors(CacheInterceptor) 10 | export class AppController { 11 | @Get() 12 | findAll() { 13 | return [{ id: 1, name: 'Nest' }]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample/26-queues/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/27-scheduling/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /integration/scopes/src/request-chain/helper/helper.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | import { REQUEST } from '@nestjs/core'; 3 | 4 | @Injectable({ scope: Scope.REQUEST }) 5 | export class HelperService { 6 | constructor(@Inject(REQUEST) public readonly request) {} 7 | 8 | public noop() {} 9 | } 10 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/unknown-module.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | 3 | export class UnknownModuleException extends RuntimeException { 4 | constructor() { 5 | super( 6 | 'Nest could not select the given module (it does not exist in current context)', 7 | ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sample/05-sql-typeorm/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/09-babel-example/src/main.js: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | console.log(`Application is running on: ${await app.getUrl()}`); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /packages/common/decorators/http/index.ts: -------------------------------------------------------------------------------- 1 | export * from './request-mapping.decorator'; 2 | export * from './route-params.decorator'; 3 | export * from './http-code.decorator'; 4 | export * from './create-route-param-metadata.decorator'; 5 | export * from './render.decorator'; 6 | export * from './header.decorator'; 7 | export * from './redirect.decorator'; 8 | -------------------------------------------------------------------------------- /packages/common/test/utils/random-string-generator.util.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { randomStringGenerator } from '../../utils/random-string-generator.util'; 3 | 4 | describe('randomStringGenerator', () => { 5 | it('should generate random string', () => { 6 | expect(randomStringGenerator()).to.be.a('string'); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/invalid-middleware.exception.ts: -------------------------------------------------------------------------------- 1 | import { INVALID_MIDDLEWARE_MESSAGE } from '../messages'; 2 | import { RuntimeException } from './runtime.exception'; 3 | 4 | export class InvalidMiddlewareException extends RuntimeException { 5 | constructor(name: string) { 6 | super(INVALID_MIDDLEWARE_MESSAGE`${name}`); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/04-grpc/src/hero/hero.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package hero; 4 | 5 | service HeroService { 6 | rpc FindOne (HeroById) returns (Hero); 7 | rpc FindMany (stream HeroById) returns (stream Hero); 8 | } 9 | 10 | message HeroById { 11 | int32 id = 1; 12 | } 13 | 14 | message Hero { 15 | int32 id = 1; 16 | string name = 2; 17 | } -------------------------------------------------------------------------------- /sample/11-swagger/README.md: -------------------------------------------------------------------------------- 1 | ### Swagger sample 2 | 3 | ### Installation 4 | 5 | `npm install` 6 | 7 | ### Running 8 | 9 | Once the application is running you can visit [http://localhost:3000/api](http://localhost:3000/api) to see the Swagger interface. 10 | 11 | See [here](https://docs.nestjs.com/recipes/swagger#bootstrap) for more information. -------------------------------------------------------------------------------- /packages/common/utils/extend-metadata.util.ts: -------------------------------------------------------------------------------- 1 | export function extendArrayMetadata>( 2 | key: string, 3 | metadata: T, 4 | target: Function, 5 | ) { 6 | const previousValue = Reflect.getMetadata(key, target) || []; 7 | const value = [...previousValue, ...metadata]; 8 | Reflect.defineMetadata(key, value, target); 9 | } 10 | -------------------------------------------------------------------------------- /sample/06-mongoose/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { MongooseModule } from '@nestjs/mongoose'; 3 | import { CatsModule } from './cats/cats.module'; 4 | 5 | @Module({ 6 | imports: [ 7 | MongooseModule.forRoot('mongodb://localhost:27017/test'), 8 | CatsModule, 9 | ], 10 | }) 11 | export class AppModule {} 12 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/cats/cats.providers.ts: -------------------------------------------------------------------------------- 1 | import { Mongoose } from 'mongoose'; 2 | import { CatSchema } from './schemas/cat.schema'; 3 | 4 | export const catsProviders = [ 5 | { 6 | provide: 'CAT_MODEL', 7 | useFactory: (mongoose: Mongoose) => mongoose.model('Cat', CatSchema), 8 | inject: ['DATABASE_CONNECTION'], 9 | }, 10 | ]; 11 | -------------------------------------------------------------------------------- /sample/26-queues/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration/graphql-code-first/src/recipes/dto/recipes.args.ts: -------------------------------------------------------------------------------- 1 | import { ArgsType, Field, Int } from '@nestjs/graphql'; 2 | import { Max, Min } from 'class-validator'; 3 | 4 | @ArgsType() 5 | export class RecipesArgs { 6 | @Field(type => Int) 7 | @Min(0) 8 | skip = 0; 9 | 10 | @Field(type => Int) 11 | @Min(1) 12 | @Max(50) 13 | take = 25; 14 | } 15 | -------------------------------------------------------------------------------- /integration/injector/src/circular/circular.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, forwardRef, Inject } from '@nestjs/common'; 2 | import { InputService } from './input.service'; 3 | 4 | @Injectable() 5 | export class CircularService { 6 | constructor( 7 | @Inject(forwardRef(() => InputService)) 8 | public readonly service: InputService, 9 | ) {} 10 | } 11 | -------------------------------------------------------------------------------- /sample/08-webpack/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/README.md: -------------------------------------------------------------------------------- 1 | ### Graphql Apollo sample 2 | 3 | ### Installation 4 | 5 | `npm install` 6 | 7 | ### Graphql Playground 8 | 9 | When the application is running, you can go to [http://localhost:3000/graphql](http://localhost:3000/graphql) to access the GraphQL Playground. See [here](https://docs.nestjs.com/graphql/quick-start#playground) for more. -------------------------------------------------------------------------------- /sample/23-graphql-code-first/src/recipes/dto/recipes.args.ts: -------------------------------------------------------------------------------- 1 | import { ArgsType, Field, Int } from '@nestjs/graphql'; 2 | import { Max, Min } from 'class-validator'; 3 | 4 | @ArgsType() 5 | export class RecipesArgs { 6 | @Field(type => Int) 7 | @Min(0) 8 | skip = 0; 9 | 10 | @Field(type => Int) 11 | @Min(1) 12 | @Max(50) 13 | take = 25; 14 | } 15 | -------------------------------------------------------------------------------- /sample/27-scheduling/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration/injector/src/circular-modules/circular.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, forwardRef, Inject } from '@nestjs/common'; 2 | import { InputService } from './input.service'; 3 | 4 | @Injectable() 5 | export class CircularService { 6 | constructor( 7 | @Inject(forwardRef(() => InputService)) 8 | public readonly service: InputService, 9 | ) {} 10 | } 11 | -------------------------------------------------------------------------------- /integration/injector/src/circular/input.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject, forwardRef } from '@nestjs/common'; 2 | import { CircularService } from './circular.service'; 3 | 4 | @Injectable() 5 | export class InputService { 6 | constructor( 7 | @Inject(forwardRef(() => CircularService)) 8 | public readonly service: CircularService, 9 | ) {} 10 | } 11 | -------------------------------------------------------------------------------- /integration/injector/src/defaults/defaults.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Optional } from '@nestjs/common'; 2 | import { CoreService } from './core.service'; 3 | 4 | @Injectable() 5 | export class DefaultsService { 6 | constructor( 7 | @Inject(CoreService) 8 | @Optional() 9 | public readonly coreService = { default: true }, 10 | ) {} 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/invalid-middleware-configuration.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | import { INVALID_MIDDLEWARE_CONFIGURATION } from '../messages'; 3 | 4 | export class InvalidMiddlewareConfigurationException extends RuntimeException { 5 | constructor() { 6 | super(INVALID_MIDDLEWARE_CONFIGURATION); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration/injector/src/circular-modules/input.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject, forwardRef } from '@nestjs/common'; 2 | import { CircularService } from './circular.service'; 3 | 4 | @Injectable() 5 | export class InputService { 6 | constructor( 7 | @Inject(forwardRef(() => CircularService)) 8 | public readonly service: CircularService, 9 | ) {} 10 | } 11 | -------------------------------------------------------------------------------- /integration/websockets/src/namespace.gateway.ts: -------------------------------------------------------------------------------- 1 | import { WebSocketGateway, SubscribeMessage } from '@nestjs/websockets'; 2 | 3 | @WebSocketGateway(8080, { 4 | namespace: 'test', 5 | }) 6 | export class NamespaceGateway { 7 | @SubscribeMessage('push') 8 | onPush(client, data) { 9 | return { 10 | event: 'pop', 11 | data, 12 | }; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/unknown-export.exception.ts: -------------------------------------------------------------------------------- 1 | import { UNKNOWN_EXPORT_MESSAGE } from '../messages'; 2 | import { RuntimeException } from './runtime.exception'; 3 | 4 | export class UnknownExportException extends RuntimeException { 5 | constructor(token: string | symbol, moduleName: string) { 6 | super(UNKNOWN_EXPORT_MESSAGE(token, moduleName)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/05-sql-typeorm/src/users/user.entity.ts: -------------------------------------------------------------------------------- 1 | import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; 2 | 3 | @Entity() 4 | export class User { 5 | @PrimaryGeneratedColumn() 6 | id: number; 7 | 8 | @Column() 9 | firstName: string; 10 | 11 | @Column() 12 | lastName: string; 13 | 14 | @Column({ default: true }) 15 | isActive: boolean; 16 | } 17 | -------------------------------------------------------------------------------- /benchmarks/nest.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, '__esModule', { value: true }); 3 | const core_1 = require('@nestjs/core'); 4 | const app_module_1 = require('./nest/app.module'); 5 | core_1.NestFactory.create(app_module_1.AppModule, { 6 | logger: false, 7 | bodyParser: false, 8 | }).then(app => app.listen(3000)); 9 | //# sourceMappingURL=main.js.map 10 | -------------------------------------------------------------------------------- /integration/nest-application/get-url/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.sayHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration/websockets/src/app.gateway.ts: -------------------------------------------------------------------------------- 1 | import { 2 | MessageBody, 3 | SubscribeMessage, 4 | WebSocketGateway, 5 | } from '@nestjs/websockets'; 6 | 7 | @WebSocketGateway(8080) 8 | export class ApplicationGateway { 9 | @SubscribeMessage('push') 10 | onPush(@MessageBody() data) { 11 | return { 12 | event: 'pop', 13 | data, 14 | }; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/10-fastify/src/cats/cats.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { Cat } from './interfaces/cat.interface'; 3 | 4 | @Injectable() 5 | export class CatsService { 6 | private readonly cats: Cat[] = []; 7 | 8 | create(cat: Cat) { 9 | this.cats.push(cat); 10 | } 11 | 12 | findAll(): Cat[] { 13 | return this.cats; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc-advanced/proto/orders/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package proto_example.orders; 3 | 4 | import public "common/item_types.proto"; 5 | import public "common/shipment_types.proto"; 6 | 7 | message Order { 8 | int32 id = 1; 9 | repeated common.items.ItemType itemTypes = 2; 10 | common.shipments.ShipmentType shipmentType = 3; 11 | } -------------------------------------------------------------------------------- /packages/common/interfaces/nest-application-context-options.interface.ts: -------------------------------------------------------------------------------- 1 | import { LoggerService, LogLevel } from '../services/logger.service'; 2 | 3 | /** 4 | * @publicApi 5 | */ 6 | export class NestApplicationContextOptions { 7 | /** 8 | * Specifies the logger to use. Pass `false` to turn off logging. 9 | */ 10 | logger?: LoggerService | LogLevel[] | boolean; 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/invalid-module.exception.ts: -------------------------------------------------------------------------------- 1 | import { INVALID_MODULE_MESSAGE } from '../messages'; 2 | import { RuntimeException } from './runtime.exception'; 3 | 4 | export class InvalidModuleException extends RuntimeException { 5 | constructor(parentModule: any, index: number, scope: any[]) { 6 | super(INVALID_MODULE_MESSAGE(parentModule, index, scope)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/core/router/request/request-providers.ts: -------------------------------------------------------------------------------- 1 | import { Provider, Scope } from '@nestjs/common'; 2 | import { REQUEST } from './request-constants'; 3 | 4 | // eslint-disable-next-line @typescript-eslint/no-empty-function 5 | const noop = () => {}; 6 | export const requestProvider: Provider = { 7 | provide: REQUEST, 8 | scope: Scope.REQUEST, 9 | useFactory: noop, 10 | }; 11 | -------------------------------------------------------------------------------- /packages/microservices/client/index.ts: -------------------------------------------------------------------------------- 1 | export * from './client-grpc'; 2 | export * from './client-kafka'; 3 | export * from './client-mqtt'; 4 | export * from './client-nats'; 5 | export * from './client-proxy'; 6 | export { ClientProxyFactory } from './client-proxy-factory'; 7 | export * from './client-redis'; 8 | export * from './client-rmq'; 9 | export * from './client-tcp'; 10 | -------------------------------------------------------------------------------- /sample/01-cats-app/src/cats/cats.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { Cat } from './interfaces/cat.interface'; 3 | 4 | @Injectable() 5 | export class CatsService { 6 | private readonly cats: Cat[] = []; 7 | 8 | create(cat: Cat) { 9 | this.cats.push(cat); 10 | } 11 | 12 | findAll(): Cat[] { 13 | return this.cats; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/generate-typings.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLDefinitionsFactory } from '@nestjs/graphql'; 2 | import { join } from 'path'; 3 | 4 | const definitionsFactory = new GraphQLDefinitionsFactory(); 5 | definitionsFactory.generate({ 6 | typePaths: ['./src/**/*.graphql'], 7 | path: join(process.cwd(), 'src/graphql.schema.ts'), 8 | outputAs: 'class', 9 | }); 10 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/src/prisma/prisma.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { Prisma } from './prisma.binding'; 3 | 4 | @Injectable() 5 | export class PrismaService extends Prisma { 6 | constructor() { 7 | super({ 8 | endpoint: 'https://eu1.prisma.sh/public-agatepuma-476/my-app/dev', 9 | debug: false, 10 | }); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sample/24-serve-static/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | app.setGlobalPrefix('api'); 7 | 8 | await app.listen(3000); 9 | console.log(`Application is running on: ${await app.getUrl()}`); 10 | } 11 | bootstrap(); 12 | -------------------------------------------------------------------------------- /integration/scopes/src/msvc/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class UsersService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | UsersService.COUNTER++; 8 | } 9 | 10 | findById(id: string) { 11 | return { id }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration/websockets/src/error.gateway.ts: -------------------------------------------------------------------------------- 1 | import { 2 | SubscribeMessage, 3 | WebSocketGateway, 4 | WsException, 5 | } from '@nestjs/websockets'; 6 | import { throwError } from 'rxjs'; 7 | 8 | @WebSocketGateway(8080) 9 | export class ErrorGateway { 10 | @SubscribeMessage('push') 11 | onPush(client, data) { 12 | return throwError(new WsException('test')); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sample/26-queues/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { AudioModule } from './audio/audio.module'; 5 | 6 | @Module({ 7 | imports: [AudioModule], 8 | controllers: [AppController], 9 | providers: [AppService], 10 | }) 11 | export class AppModule {} 12 | -------------------------------------------------------------------------------- /integration/hello-world/src/host/host.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HostController } from './host.controller'; 3 | import { HostService } from './host.service'; 4 | import { UsersService } from './users/users.service'; 5 | 6 | @Module({ 7 | controllers: [HostController], 8 | providers: [HostService, UsersService], 9 | }) 10 | export class HostModule {} 11 | -------------------------------------------------------------------------------- /integration/injector/src/circular-modules/input.module.ts: -------------------------------------------------------------------------------- 1 | import { Module, forwardRef } from '@nestjs/common'; 2 | import { CircularModule } from './circular.module'; 3 | import { InputService } from './input.service'; 4 | 5 | @Module({ 6 | imports: [forwardRef(() => CircularModule)], 7 | providers: [InputService], 8 | exports: [InputService], 9 | }) 10 | export class InputModule {} 11 | -------------------------------------------------------------------------------- /integration/scopes/src/hello/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class UsersService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | UsersService.COUNTER++; 8 | } 9 | 10 | findById(id: string) { 11 | return { id }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration/scopes/src/transient/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class UsersService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | UsersService.COUNTER++; 8 | } 9 | 10 | findById(id: string) { 11 | return { id }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/undefined-module.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | import { UNDEFINED_MODULE_MESSAGE } from '../messages'; 3 | 4 | export class UndefinedModuleException extends RuntimeException { 5 | constructor(parentModule: any, index: number, scope: any[]) { 6 | super(UNDEFINED_MODULE_MESSAGE(parentModule, index, scope)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/core/injector/inquirer/inquirer-providers.ts: -------------------------------------------------------------------------------- 1 | import { Provider, Scope } from '@nestjs/common'; 2 | import { INQUIRER } from './inquirer-constants'; 3 | 4 | // eslint-disable-next-line @typescript-eslint/no-empty-function 5 | const noop = () => {}; 6 | export const inquirerProvider: Provider = { 7 | provide: INQUIRER, 8 | scope: Scope.TRANSIENT, 9 | useFactory: noop, 10 | }; 11 | -------------------------------------------------------------------------------- /sample/18-context/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | import { AppService } from './app.service'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.createApplicationContext(AppModule); 7 | const appService = app.get(AppService); 8 | console.log(appService.getHello()); 9 | } 10 | bootstrap(); 11 | -------------------------------------------------------------------------------- /integration/graphql-code-first/src/main.ts: -------------------------------------------------------------------------------- 1 | import { ValidationPipe } from '@nestjs/common'; 2 | import { NestFactory } from '@nestjs/core'; 3 | import { ApplicationModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(ApplicationModule); 7 | app.useGlobalPipes(new ValidationPipe()); 8 | await app.listen(3000); 9 | } 10 | bootstrap(); 11 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-hello/hello.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class HelloService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | HelloService.COUNTER++; 8 | } 9 | 10 | greeting(): string { 11 | return 'Hello world!'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-hello/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class UsersService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | UsersService.COUNTER++; 8 | } 9 | 10 | findById(id: string) { 11 | return { id }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/common/interfaces/hooks/on-application-bootstrap.interface.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface defining method called once the application has fully started and 3 | * is bootstrapped. 4 | * 5 | * @see [Lifecycle Events](https://docs.nestjs.com/fundamentals/lifecycle-events) 6 | * 7 | * @publicApi 8 | */ 9 | export interface OnApplicationBootstrap { 10 | onApplicationBootstrap(): any; 11 | } 12 | -------------------------------------------------------------------------------- /integration/hello-world/src/hello/hello.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HelloController } from './hello.controller'; 3 | import { HelloService } from './hello.service'; 4 | import { UsersService } from './users/users.service'; 5 | 6 | @Module({ 7 | controllers: [HelloController], 8 | providers: [HelloService, UsersService], 9 | }) 10 | export class HelloModule {} 11 | -------------------------------------------------------------------------------- /integration/injector/src/circular-modules/circular.module.ts: -------------------------------------------------------------------------------- 1 | import { Module, forwardRef } from '@nestjs/common'; 2 | import { CircularService } from './circular.service'; 3 | import { InputModule } from './input.module'; 4 | 5 | @Module({ 6 | imports: [forwardRef(() => InputModule)], 7 | providers: [CircularService], 8 | exports: [CircularService], 9 | }) 10 | export class CircularModule {} 11 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-transient/hello.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class HelloService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | HelloService.COUNTER++; 8 | } 9 | 10 | greeting(): string { 11 | return 'Hello world!'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-transient/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, Scope } from '@nestjs/common'; 2 | 3 | @Injectable({ scope: Scope.REQUEST }) 4 | export class UsersService { 5 | static COUNTER = 0; 6 | constructor(@Inject('META') private readonly meta) { 7 | UsersService.COUNTER++; 8 | } 9 | 10 | findById(id: string) { 11 | return { id }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/common/interfaces/middleware/middleware-configuration.interface.ts: -------------------------------------------------------------------------------- 1 | import { RequestMethod } from '../../enums'; 2 | import { Type } from '../type.interface'; 3 | 4 | export interface RouteInfo { 5 | path: string; 6 | method: RequestMethod; 7 | } 8 | 9 | export interface MiddlewareConfiguration { 10 | middleware: T; 11 | forRoutes: (Type | string | RouteInfo)[]; 12 | } 13 | -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/src/photo/photo.entity.ts: -------------------------------------------------------------------------------- 1 | import { Column, Entity, ObjectID, ObjectIdColumn } from 'typeorm'; 2 | 3 | @Entity() 4 | export class Photo { 5 | @ObjectIdColumn() 6 | id: ObjectID; 7 | 8 | @Column() 9 | name: string; 10 | 11 | @Column() 12 | description: string; 13 | 14 | @Column() 15 | filename: string; 16 | 17 | @Column() 18 | isPublished: boolean; 19 | } 20 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/src/recipes/recipes.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { DateScalar } from '../common/scalars/date.scalar'; 3 | import { RecipesResolver } from './recipes.resolver'; 4 | import { RecipesService } from './recipes.service'; 5 | 6 | @Module({ 7 | providers: [RecipesResolver, RecipesService, DateScalar], 8 | }) 9 | export class RecipesModule {} 10 | -------------------------------------------------------------------------------- /packages/common/test/utils/forward-ref.util.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { forwardRef } from '../../utils/forward-ref.util'; 3 | 4 | describe('forwardRef', () => { 5 | it('should return object with forwardRef property', () => { 6 | const fn = () => ({}); 7 | const referenceFn = forwardRef(() => fn); 8 | expect(referenceFn.forwardRef()).to.be.eql(fn); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/core/discovery/discovery-module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { MetadataScanner } from '../metadata-scanner'; 3 | import { DiscoveryService } from './discovery-service'; 4 | 5 | /** 6 | * @publicApi 7 | */ 8 | @Module({ 9 | providers: [MetadataScanner, DiscoveryService], 10 | exports: [MetadataScanner, DiscoveryService], 11 | }) 12 | export class DiscoveryModule {} 13 | -------------------------------------------------------------------------------- /packages/core/helpers/get-class-scope.ts: -------------------------------------------------------------------------------- 1 | import { Scope } from '@nestjs/common'; 2 | import { SCOPE_OPTIONS_METADATA } from '@nestjs/common/constants'; 3 | import { Type } from '@nestjs/common/interfaces/type.interface'; 4 | 5 | export function getClassScope(provider: Type): Scope { 6 | const metadata = Reflect.getMetadata(SCOPE_OPTIONS_METADATA, provider); 7 | return metadata && metadata.scope; 8 | } 9 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-kafka-client-topic.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidKafkaClientTopicException extends RuntimeException { 4 | constructor(topic?: string) { 5 | super( 6 | `The client consumer did not subscribe to the corresponding reply topic (${topic}).`, 7 | ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sample/06-mongoose/src/cats/schemas/cat.schema.ts: -------------------------------------------------------------------------------- 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; 2 | import { Document } from 'mongoose'; 3 | 4 | @Schema() 5 | export class Cat extends Document { 6 | @Prop() 7 | name: string; 8 | 9 | @Prop() 10 | age: number; 11 | 12 | @Prop() 13 | breed: string; 14 | } 15 | 16 | export const CatSchema = SchemaFactory.createForClass(Cat); 17 | -------------------------------------------------------------------------------- /sample/22-graphql-prisma/.graphqlconfig.yml: -------------------------------------------------------------------------------- 1 | projects: 2 | database: 3 | schemaPath: src/prisma/prisma-types.graphql 4 | extensions: 5 | endpoints: 6 | default: https://eu1.prisma.sh/public-agatepuma-476/my-app/dev 7 | codegen: 8 | - generator: prisma-binding 9 | language: typescript 10 | output: 11 | binding: src/prisma/prisma.binding.ts 12 | -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/cats/cats.guard.ts: -------------------------------------------------------------------------------- 1 | import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; 2 | import { GqlExecutionContext } from '@nestjs/graphql'; 3 | 4 | @Injectable() 5 | export class CatsGuard implements CanActivate { 6 | canActivate(context: ExecutionContext): boolean { 7 | const ctx = GqlExecutionContext.create(context); 8 | return true; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /integration/mongoose/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { MongooseModule } from '@nestjs/mongoose'; 3 | import { CatsModule } from './cats/cats.module'; 4 | 5 | @Module({ 6 | imports: [ 7 | MongooseModule.forRoot('mongodb://localhost:27017/test', { 8 | useNewUrlParser: true, 9 | }), 10 | CatsModule, 11 | ], 12 | }) 13 | export class ApplicationModule {} 14 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/undefined-forwardref.exception.ts: -------------------------------------------------------------------------------- 1 | import { UNDEFINED_FORWARDREF_MESSAGE } from '../messages'; 2 | import { RuntimeException } from './runtime.exception'; 3 | import { Type } from '@nestjs/common'; 4 | 5 | export class UndefinedForwardRefException extends RuntimeException { 6 | constructor(scope: Type[]) { 7 | super(UNDEFINED_FORWARDREF_MESSAGE(scope)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/platform-express/multer/multer/multer.constants.ts: -------------------------------------------------------------------------------- 1 | export const multerExceptions = { 2 | LIMIT_PART_COUNT: 'Too many parts', 3 | LIMIT_FILE_SIZE: 'File too large', 4 | LIMIT_FILE_COUNT: 'Too many files', 5 | LIMIT_FIELD_KEY: 'Field name too long', 6 | LIMIT_FIELD_VALUE: 'Field value too long', 7 | LIMIT_FIELD_COUNT: 'Too many fields', 8 | LIMIT_UNEXPECTED_FILE: 'Unexpected field', 9 | }; 10 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/cats/cats.guard.ts: -------------------------------------------------------------------------------- 1 | import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; 2 | import { GqlExecutionContext } from '@nestjs/graphql'; 3 | 4 | @Injectable() 5 | export class CatsGuard implements CanActivate { 6 | canActivate(context: ExecutionContext): boolean { 7 | const ctx = GqlExecutionContext.create(context); 8 | return true; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.circleci/install-wrk.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | cd "$(dirname "$0")" 4 | 5 | # based on https://medium.com/@felipedutratine/intelligent-benchmark-with-wrk-163986c1587f 6 | 7 | cd /tmp/ 8 | sudo apt-get install build-essential libssl-dev git -y 9 | git clone https://github.com/wg/wrk.git wrk 10 | cd wrk 11 | sudo make 12 | # move the executable to somewhere in your PATH, ex: 13 | sudo cp wrk /usr/local/bin -------------------------------------------------------------------------------- /sample/04-grpc/src/grpc-client.options.ts: -------------------------------------------------------------------------------- 1 | import { ClientOptions, Transport } from '@nestjs/microservices'; 2 | import { join } from 'path'; 3 | 4 | export const grpcClientOptions: ClientOptions = { 5 | transport: Transport.GRPC, 6 | options: { 7 | package: 'hero', // ['hero', 'hero2'] 8 | protoPath: join(__dirname, './hero/hero.proto'), // ['./hero/hero.proto', './hero/hero2.proto'] 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/cats/cats.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | getCats: [Cat] 3 | cat(id: ID!): Cat 4 | } 5 | 6 | type Mutation { 7 | createCat(createCatInput: CreateCatInput): Cat 8 | } 9 | 10 | type Subscription { 11 | catCreated: Cat 12 | } 13 | 14 | type Cat { 15 | id: Int 16 | name: String 17 | age: Int 18 | } 19 | 20 | input CreateCatInput { 21 | name: String 22 | age: Int 23 | } 24 | -------------------------------------------------------------------------------- /integration/websockets/src/core.gateway.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ConnectedSocket, 3 | MessageBody, 4 | SubscribeMessage, 5 | WebSocketGateway, 6 | } from '@nestjs/websockets'; 7 | 8 | @WebSocketGateway(8090) 9 | export class CoreGateway { 10 | @SubscribeMessage('push') 11 | onPush(@ConnectedSocket() client, @MessageBody() data) { 12 | return { 13 | event: 'pop', 14 | data, 15 | }; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/common/interfaces/hooks/on-application-shutdown.interface.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface defining method to respond to system signals (when application gets 3 | * shutdown by, e.g., SIGTERM) 4 | * 5 | * @see [Lifecycle Events](https://docs.nestjs.com/fundamentals/lifecycle-events) 6 | * 7 | * @publicApi 8 | */ 9 | export interface OnApplicationShutdown { 10 | onApplicationShutdown(signal?: string): any; 11 | } 12 | -------------------------------------------------------------------------------- /packages/common/serializer/decorators/serialize-options.decorator.ts: -------------------------------------------------------------------------------- 1 | import { SetMetadata } from '../../decorators'; 2 | import { ClassTransformOptions } from '../../interfaces/external/class-transform-options.interface'; 3 | import { CLASS_SERIALIZER_OPTIONS } from '../class-serializer.constants'; 4 | 5 | export const SerializeOptions = (options: ClassTransformOptions) => 6 | SetMetadata(CLASS_SERIALIZER_OPTIONS, options); 7 | -------------------------------------------------------------------------------- /integration/graphql-code-first/src/common/filters/unauthorized.filter.ts: -------------------------------------------------------------------------------- 1 | import { ArgumentsHost, Catch, UnauthorizedException } from '@nestjs/common'; 2 | import { GqlExceptionFilter } from '@nestjs/graphql'; 3 | 4 | @Catch(UnauthorizedException) 5 | export class UnauthorizedFilter implements GqlExceptionFilter { 6 | catch(exception: any, host: ArgumentsHost) { 7 | return new Error('Unauthorized error'); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /integration/injector/src/properties/properties.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable } from '@nestjs/common'; 2 | import { DependencyService } from './dependency.service'; 3 | 4 | export const SYMBOL_TOKEN = Symbol('token'); 5 | 6 | @Injectable() 7 | export class PropertiesService { 8 | @Inject() service: DependencyService; 9 | @Inject('token') token: boolean; 10 | @Inject(SYMBOL_TOKEN) symbolToken: boolean; 11 | } 12 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc/math.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package math; 4 | 5 | service Math { 6 | rpc Sum (RequestSum) returns (SumResult); 7 | rpc SumStream(stream RequestSum) returns(stream SumResult); 8 | rpc SumStreamPass(stream RequestSum) returns(stream SumResult); 9 | } 10 | 11 | message SumResult { 12 | int32 result = 1; 13 | } 14 | 15 | message RequestSum { 16 | repeated int32 data = 1; 17 | } -------------------------------------------------------------------------------- /packages/microservices/context/rpc-metadata-constants.ts: -------------------------------------------------------------------------------- 1 | import { RpcParamtype } from '../enums/rpc-paramtype.enum'; 2 | 3 | export const DEFAULT_CALLBACK_METADATA = { 4 | [`${RpcParamtype.PAYLOAD}:0`]: { index: 0, data: undefined, pipes: [] }, 5 | }; 6 | export const DEFAULT_GRPC_CALLBACK_METADATA = { 7 | [`${RpcParamtype.CONTEXT}:1`]: { index: 1, data: undefined, pipes: [] }, 8 | ...DEFAULT_CALLBACK_METADATA, 9 | }; 10 | -------------------------------------------------------------------------------- /packages/microservices/ctx-host/nats.context.ts: -------------------------------------------------------------------------------- 1 | import { BaseRpcContext } from './base-rpc.context'; 2 | 3 | type NatsContextArgs = [string]; 4 | 5 | export class NatsContext extends BaseRpcContext { 6 | constructor(args: NatsContextArgs) { 7 | super(args); 8 | } 9 | 10 | /** 11 | * Returns the name of the subject. 12 | */ 13 | getSubject() { 14 | return this.args[0]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /integration/injector/src/circular-structure-dynamic-module/circular.module.ts: -------------------------------------------------------------------------------- 1 | import { DynamicModule } from '@nestjs/common'; 2 | import { InputService } from './input.service'; 3 | 4 | export class CircularModule { 5 | static forRoot(): DynamicModule { 6 | const a = { 7 | module: CircularModule, 8 | providers: [InputService], 9 | b: null, 10 | }; 11 | a.b = a; 12 | return a; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/microservices/ctx-host/redis.context.ts: -------------------------------------------------------------------------------- 1 | import { BaseRpcContext } from './base-rpc.context'; 2 | 3 | type RedisContextArgs = [string]; 4 | 5 | export class RedisContext extends BaseRpcContext { 6 | constructor(args: RedisContextArgs) { 7 | super(args); 8 | } 9 | 10 | /** 11 | * Returns the name of the channel. 12 | */ 13 | getChannel() { 14 | return this.args[0]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/testing/interfaces/override-by.interface.ts: -------------------------------------------------------------------------------- 1 | import { TestingModuleBuilder } from '../testing-module.builder'; 2 | import { OverrideByFactoryOptions } from './override-by-factory-options.interface'; 3 | 4 | export interface OverrideBy { 5 | useValue: (value: any) => TestingModuleBuilder; 6 | useFactory: (options: OverrideByFactoryOptions) => TestingModuleBuilder; 7 | useClass: (metatype: any) => TestingModuleBuilder; 8 | } 9 | -------------------------------------------------------------------------------- /sample/01-cats-app/jest.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": [ 3 | "ts", 4 | "tsx", 5 | "js", 6 | "json" 7 | ], 8 | "transform": { 9 | "^.+\\.tsx?$": "ts-jest" 10 | }, 11 | "testRegex": "/src/.*\\.(test|spec).(ts|tsx|js)$", 12 | "collectCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"], 13 | "coverageReporters": ["json", "lcov"] 14 | } -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { GraphQLModule } from '@nestjs/graphql'; 3 | import { CatsModule } from './cats/cats.module'; 4 | 5 | @Module({ 6 | imports: [ 7 | CatsModule, 8 | GraphQLModule.forRoot({ 9 | typePaths: ['./**/*.graphql'], 10 | installSubscriptionHandlers: true, 11 | }), 12 | ], 13 | }) 14 | export class AppModule {} 15 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { ConfigModule } from './config/config.module'; 5 | 6 | @Module({ 7 | imports: [ConfigModule.register({ folder: './config' })], 8 | controllers: [AppController], 9 | providers: [AppService], 10 | }) 11 | export class AppModule {} 12 | -------------------------------------------------------------------------------- /integration/scopes/src/msvc/http.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { ClientProxyFactory, Transport } from '@nestjs/microservices'; 3 | 4 | @Controller() 5 | export class HttpController { 6 | @Get('hello') 7 | testMsvc() { 8 | const client = ClientProxyFactory.create({ 9 | transport: Transport.TCP, 10 | }); 11 | return client.send('test', { test: true }); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/common/enums/shutdown-signal.enum.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * System signals which shut down a process 3 | */ 4 | export enum ShutdownSignal { 5 | SIGHUP = 'SIGHUP', 6 | SIGINT = 'SIGINT', 7 | SIGQUIT = 'SIGQUIT', 8 | SIGILL = 'SIGILL', 9 | SIGTRAP = 'SIGTRAP', 10 | SIGABRT = 'SIGABRT', 11 | SIGBUS = 'SIGBUS', 12 | SIGFPE = 'SIGFPE', 13 | SIGSEGV = 'SIGSEGV', 14 | SIGUSR2 = 'SIGUSR2', 15 | SIGTERM = 'SIGTERM', 16 | } 17 | -------------------------------------------------------------------------------- /packages/websockets/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Nest @websockets 3 | * Copyright(c) 2017 - 2020 Kamil Mysliwiec 4 | * https://nestjs.com 5 | * MIT Licensed 6 | */ 7 | import 'reflect-metadata'; 8 | 9 | export * from './adapters'; 10 | export * from './decorators'; 11 | export * from './errors'; 12 | export * from './exceptions'; 13 | export { MessageMappingProperties } from './gateway-metadata-explorer'; 14 | export * from './interfaces'; 15 | -------------------------------------------------------------------------------- /integration/graphql-code-first/src/recipes/models/recipe.ts: -------------------------------------------------------------------------------- 1 | import { Field, ID, ObjectType } from '@nestjs/graphql'; 2 | 3 | @ObjectType() 4 | export class Recipe { 5 | @Field(type => ID) 6 | id: string; 7 | 8 | @Field() 9 | title: string; 10 | 11 | @Field({ nullable: true }) 12 | description?: string; 13 | 14 | @Field() 15 | creationDate: Date; 16 | 17 | @Field(type => [String]) 18 | ingredients: string[]; 19 | } 20 | -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/config.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { GqlModuleOptions, GqlOptionsFactory } from '@nestjs/graphql'; 3 | import { join } from 'path'; 4 | 5 | @Injectable() 6 | export class ConfigService implements GqlOptionsFactory { 7 | createGqlOptions(): GqlModuleOptions { 8 | return { 9 | typePaths: [join(__dirname, '**', '*.graphql')], 10 | }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /integration/typeorm/src/photo/photo.entity.ts: -------------------------------------------------------------------------------- 1 | import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; 2 | 3 | @Entity() 4 | export class Photo { 5 | @PrimaryGeneratedColumn() id: number; 6 | 7 | @Column({ length: 500 }) 8 | name: string; 9 | 10 | @Column('text') description: string; 11 | 12 | @Column() filename: string; 13 | 14 | @Column('int') views: number; 15 | 16 | @Column() isPublished: boolean; 17 | } 18 | -------------------------------------------------------------------------------- /packages/microservices/errors/invalid-kafka-client-topic-partition.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; 2 | 3 | export class InvalidKafkaClientTopicPartitionException extends RuntimeException { 4 | constructor(topic?: string) { 5 | super( 6 | `The client consumer subscribed to the topic (${topic}) whcih is not assigned to any partitions.`, 7 | ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sample/20-cache/src/main.ts: -------------------------------------------------------------------------------- 1 | import { ValidationPipe } from '@nestjs/common'; 2 | import { NestFactory } from '@nestjs/core'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | app.useGlobalPipes(new ValidationPipe()); 8 | 9 | await app.listen(3000); 10 | console.log(`Application is running on: ${await app.getUrl()}`); 11 | } 12 | bootstrap(); 13 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { GraphQLModule } from '@nestjs/graphql'; 3 | import { RecipesModule } from './recipes/recipes.module'; 4 | 5 | @Module({ 6 | imports: [ 7 | RecipesModule, 8 | GraphQLModule.forRoot({ 9 | installSubscriptionHandlers: true, 10 | autoSchemaFile: 'schema.gql', 11 | }), 12 | ], 13 | }) 14 | export class AppModule {} 15 | -------------------------------------------------------------------------------- /integration/graphql-schema-first/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { GraphQLModule } from '@nestjs/graphql'; 3 | import { join } from 'path'; 4 | import { CatsModule } from './cats/cats.module'; 5 | 6 | @Module({ 7 | imports: [ 8 | CatsModule, 9 | GraphQLModule.forRoot({ 10 | typePaths: [join(__dirname, '**', '*.graphql')], 11 | }), 12 | ], 13 | }) 14 | export class ApplicationModule {} 15 | -------------------------------------------------------------------------------- /integration/injector/src/circular-properties/input-properties.module.ts: -------------------------------------------------------------------------------- 1 | import { forwardRef, Module } from '@nestjs/common'; 2 | import { CircularPropertiesModule } from './circular-properties.module'; 3 | import { InputService } from './input.service'; 4 | 5 | @Module({ 6 | imports: [forwardRef(() => CircularPropertiesModule)], 7 | providers: [InputService], 8 | exports: [InputService], 9 | }) 10 | export class InputPropertiesModule {} 11 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/request-context.interface.ts: -------------------------------------------------------------------------------- 1 | import { BaseRpcContext } from '../ctx-host/base-rpc.context'; 2 | 3 | export interface RequestContext< 4 | TData = any, 5 | TContext extends BaseRpcContext = any 6 | > { 7 | pattern: string | Record; 8 | data: TData; 9 | context?: TContext; 10 | 11 | getData(): TData; 12 | getPattern(): string | Record; 13 | getContext(): TContext; 14 | } 15 | -------------------------------------------------------------------------------- /sample/01-cats-app/e2e/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": [ 3 | "ts", 4 | "tsx", 5 | "js", 6 | "json" 7 | ], 8 | "transform": { 9 | "^.+\\.tsx?$": "ts-jest" 10 | }, 11 | "testRegex": "/e2e/.*\\.(e2e-test|e2e-spec).(ts|tsx|js)$", 12 | "collectCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"], 13 | "coverageReporters": ["json", "lcov"] 14 | } -------------------------------------------------------------------------------- /sample/01-cats-app/src/main.ts: -------------------------------------------------------------------------------- 1 | import { ValidationPipe } from '@nestjs/common'; 2 | import { NestFactory } from '@nestjs/core'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | app.useGlobalPipes(new ValidationPipe()); 8 | 9 | await app.listen(3000); 10 | console.log(`Application is running on: ${await app.getUrl()}`); 11 | } 12 | bootstrap(); 13 | -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/src/photo/photo.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { PhotoService } from './photo.service'; 3 | import { Photo } from './photo.entity'; 4 | 5 | @Controller('photo') 6 | export class PhotoController { 7 | constructor(private readonly photoService: PhotoService) {} 8 | 9 | @Get() 10 | findAll(): Promise { 11 | return this.photoService.findAll(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sample/21-serializer/src/main.ts: -------------------------------------------------------------------------------- 1 | import { ValidationPipe } from '@nestjs/common'; 2 | import { NestFactory } from '@nestjs/core'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | app.useGlobalPipes(new ValidationPipe()); 8 | 9 | await app.listen(3000); 10 | console.log(`Application is running on: ${await app.getUrl()}`); 11 | } 12 | bootstrap(); 13 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/src/recipes/models/recipe.model.ts: -------------------------------------------------------------------------------- 1 | import { Field, ID, ObjectType } from '@nestjs/graphql'; 2 | 3 | @ObjectType() 4 | export class Recipe { 5 | @Field(type => ID) 6 | id: string; 7 | 8 | @Field() 9 | title: string; 10 | 11 | @Field({ nullable: true }) 12 | description?: string; 13 | 14 | @Field() 15 | creationDate: Date; 16 | 17 | @Field(type => [String]) 18 | ingredients: string[]; 19 | } 20 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/unknown-element.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | 3 | export class UnknownElementException extends RuntimeException { 4 | constructor(name?: string | symbol) { 5 | name = name && name.toString(); 6 | super( 7 | `Nest could not find ${ 8 | name || 'given' 9 | } element (this provider does not exist in the current context)`, 10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sample/03-microservices/src/common/filters/rpc-exception.filter.ts: -------------------------------------------------------------------------------- 1 | import { Catch, RpcExceptionFilter } from '@nestjs/common'; 2 | import { Observable, throwError } from 'rxjs'; 3 | import { RpcException } from '@nestjs/microservices'; 4 | 5 | @Catch(RpcException) 6 | export class ExceptionFilter implements RpcExceptionFilter { 7 | catch(exception: RpcException): Observable { 8 | return throwError(exception.getError()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sample/16-gateways-ws/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { WsAdapter } from '@nestjs/platform-ws'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | app.useWebSocketAdapter(new WsAdapter(app)); 8 | 9 | await app.listen(3000); 10 | console.log(`Application is running on: ${await app.getUrl()}`); 11 | } 12 | bootstrap(); 13 | -------------------------------------------------------------------------------- /sample/25-dynamic-modules/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { ConfigService } from './config/config.service'; 3 | 4 | @Injectable() 5 | export class AppService { 6 | private helloMessage: string; 7 | 8 | constructor(configService: ConfigService) { 9 | this.helloMessage = configService.get('HELLO_MESSAGE'); 10 | } 11 | 12 | getHello(): string { 13 | return this.helloMessage; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration/injector/src/circular-properties/circular-properties.module.ts: -------------------------------------------------------------------------------- 1 | import { forwardRef, Module } from '@nestjs/common'; 2 | import { CircularService } from './circular.service'; 3 | import { InputPropertiesModule } from './input-properties.module'; 4 | 5 | @Module({ 6 | imports: [forwardRef(() => InputPropertiesModule)], 7 | providers: [CircularService], 8 | exports: [CircularService], 9 | }) 10 | export class CircularPropertiesModule {} 11 | -------------------------------------------------------------------------------- /integration/microservices/src/grpc-advanced/proto/orders/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import "orders/message.proto"; 3 | package proto_example.orders; 4 | 5 | service OrderService { 6 | rpc Find(Order) returns (Order); 7 | rpc Sync(stream Order) returns (stream Order); 8 | rpc SyncCall(stream Order) returns (stream Order); 9 | rpc StreamReq(stream Order) returns (Order); 10 | rpc StreamReqCall(stream Order) returns (Order); 11 | } -------------------------------------------------------------------------------- /integration/scopes/src/inject-inquirer/hello-transient/hello-transient.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { TransientLogger } from './transient-logger.service'; 3 | 4 | @Injectable() 5 | export class HelloTransientService { 6 | static logger = { feature: 'transient' }; 7 | 8 | constructor(private readonly logger: TransientLogger) {} 9 | 10 | greeting() { 11 | this.logger.log('Hello transient!'); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sample/11-swagger/src/cats/classes/cat.class.ts: -------------------------------------------------------------------------------- 1 | import { ApiProperty } from '@nestjs/swagger'; 2 | 3 | export class Cat { 4 | @ApiProperty({ example: 'Kitty', description: 'The name of the Cat' }) 5 | name: string; 6 | 7 | @ApiProperty({ example: 1, description: 'The age of the Cat' }) 8 | age: number; 9 | 10 | @ApiProperty({ 11 | example: 'Maine Coon', 12 | description: 'The breed of the Cat', 13 | }) 14 | breed: string; 15 | } 16 | -------------------------------------------------------------------------------- /sample/12-graphql-schema-first/src/main.ts: -------------------------------------------------------------------------------- 1 | import { ValidationPipe } from '@nestjs/common'; 2 | import { NestFactory } from '@nestjs/core'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | app.useGlobalPipes(new ValidationPipe()); 8 | 9 | await app.listen(3000); 10 | console.log(`Application is running on: ${await app.getUrl()}`); 11 | } 12 | bootstrap(); 13 | -------------------------------------------------------------------------------- /sample/19-auth-jwt/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { AuthModule } from './auth/auth.module'; 5 | import { UsersModule } from './users/users.module'; 6 | 7 | @Module({ 8 | imports: [AuthModule, UsersModule], 9 | controllers: [AppController], 10 | providers: [AppService], 11 | }) 12 | export class AppModule {} 13 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/src/main.ts: -------------------------------------------------------------------------------- 1 | import { ValidationPipe } from '@nestjs/common'; 2 | import { NestFactory } from '@nestjs/core'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | app.useGlobalPipes(new ValidationPipe()); 8 | 9 | await app.listen(3000); 10 | console.log(`Application is running on: ${await app.getUrl()}`); 11 | } 12 | bootstrap(); 13 | -------------------------------------------------------------------------------- /tools/gulp/util/task-helpers.ts: -------------------------------------------------------------------------------- 1 | import { readdirSync, statSync } from 'fs'; 2 | import { join } from 'path'; 3 | 4 | function isDirectory(path: string) { 5 | return statSync(path).isDirectory(); 6 | } 7 | 8 | export function getFolders(dir: string) { 9 | return readdirSync(dir).filter(file => isDirectory(join(dir, file))); 10 | } 11 | 12 | export function getDirs(base: string) { 13 | return getFolders(base).map(path => `${base}/${path}`); 14 | } 15 | -------------------------------------------------------------------------------- /sample/20-cache/jest.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": [ 3 | "ts", 4 | "tsx", 5 | "js", 6 | "json" 7 | ], 8 | "transform": { 9 | "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" 10 | }, 11 | "testRegex": "/src/.*\\.(test|spec).(ts|tsx|js)$", 12 | "collectCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"], 13 | "coverageReporters": ["json", "lcov"] 14 | } -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /** 3 | * Load the TypeScript compiler, then load the TypeScript gulpfile which simply loads all 4 | * the tasks. The tasks are really inside tools/gulp/tasks. 5 | */ 6 | 7 | const path = require('path'); 8 | 9 | const projectDir = __dirname; 10 | const tsconfigPath = path.join(projectDir, 'tools/gulp/tsconfig.json'); 11 | 12 | require('ts-node').register({ 13 | project: tsconfigPath 14 | }); 15 | 16 | require('./tools/gulp/gulpfile'); -------------------------------------------------------------------------------- /integration/hello-world/src/hello/users/user-by-id.pipe.ts: -------------------------------------------------------------------------------- 1 | import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common'; 2 | import { UsersService } from './users.service'; 3 | 4 | @Injectable() 5 | export class UserByIdPipe implements PipeTransform { 6 | constructor(private readonly usersService: UsersService) {} 7 | 8 | transform(value: string, metadata: ArgumentMetadata) { 9 | return this.usersService.findById(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /integration/hello-world/src/host/users/user-by-id.pipe.ts: -------------------------------------------------------------------------------- 1 | import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common'; 2 | import { UsersService } from './users.service'; 3 | 4 | @Injectable() 5 | export class UserByIdPipe implements PipeTransform { 6 | constructor(private readonly usersService: UsersService) {} 7 | 8 | transform(value: string, metadata: ArgumentMetadata) { 9 | return this.usersService.findById(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/common/interfaces/hooks/on-destroy.interface.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface defining method called just before Nest destroys the host module 3 | * (`app.close()` method has been evaluated). Use to perform cleanup on 4 | * resources (e.g., Database connections). 5 | * 6 | * @see [Lifecycle Events](https://docs.nestjs.com/fundamentals/lifecycle-events) 7 | * 8 | * @publicApi 9 | */ 10 | export interface OnModuleDestroy { 11 | onModuleDestroy(): any; 12 | } 13 | -------------------------------------------------------------------------------- /packages/common/test/decorators/global.decorator.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { GLOBAL_MODULE_METADATA } from '../../constants'; 3 | import { Global } from '../../index'; 4 | 5 | describe('@Global', () => { 6 | @Global() 7 | class Test {} 8 | 9 | it('should enrich metatype with GlobalModule metadata', () => { 10 | const isGlobal = Reflect.getMetadata(GLOBAL_MODULE_METADATA, Test); 11 | expect(isGlobal).to.be.true; 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/microservices/interfaces/serializer.interface.ts: -------------------------------------------------------------------------------- 1 | import { 2 | OutgoingEvent, 3 | OutgoingRequest, 4 | OutgoingResponse, 5 | } from './packet.interface'; 6 | 7 | export interface Serializer { 8 | serialize(value: TInput): TOutput; 9 | } 10 | 11 | export type ProducerSerializer = Serializer< 12 | OutgoingEvent | OutgoingRequest, 13 | any 14 | >; 15 | export type ConsumerSerializer = Serializer; 16 | -------------------------------------------------------------------------------- /packages/websockets/decorators/gateway-server.decorator.ts: -------------------------------------------------------------------------------- 1 | import { GATEWAY_SERVER_METADATA } from '../constants'; 2 | 3 | /** 4 | * Attaches native Web Socket Server to a given property. 5 | */ 6 | export const WebSocketServer = (): PropertyDecorator => { 7 | return (target: object, propertyKey: string | symbol) => { 8 | Reflect.set(target, propertyKey, null); 9 | Reflect.defineMetadata(GATEWAY_SERVER_METADATA, true, target, propertyKey); 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /sample/03-microservices/src/math/math.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ClientsModule, Transport } from '@nestjs/microservices'; 3 | import { MATH_SERVICE } from './math.constants'; 4 | import { MathController } from './math.controller'; 5 | 6 | @Module({ 7 | imports: [ 8 | ClientsModule.register([{ name: MATH_SERVICE, transport: Transport.TCP }]), 9 | ], 10 | controllers: [MathController], 11 | }) 12 | export class MathModule {} 13 | -------------------------------------------------------------------------------- /sample/21-serializer/jest.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": [ 3 | "ts", 4 | "tsx", 5 | "js", 6 | "json" 7 | ], 8 | "transform": { 9 | "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" 10 | }, 11 | "testRegex": "/src/.*\\.(test|spec).(ts|tsx|js)$", 12 | "collectCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"], 13 | "coverageReporters": ["json", "lcov"] 14 | } -------------------------------------------------------------------------------- /sample/27-scheduling/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ScheduleModule } from '@nestjs/schedule'; 3 | import { AppController } from './app.controller'; 4 | import { AppService } from './app.service'; 5 | import { TasksModule } from './tasks/tasks.module'; 6 | 7 | @Module({ 8 | imports: [ScheduleModule.forRoot(), TasksModule], 9 | controllers: [AppController], 10 | providers: [AppService], 11 | }) 12 | export class AppModule {} 13 | -------------------------------------------------------------------------------- /integration/scopes/src/request-chain/request-chain.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { HelperService } from './helper/helper.service'; 3 | 4 | @Injectable() 5 | export class RequestChainService { 6 | static COUNTER = 0; 7 | constructor(private readonly helperService: HelperService) { 8 | helperService.noop(); 9 | RequestChainService.COUNTER += 1; 10 | } 11 | 12 | call() { 13 | this.helperService.noop(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration/typeorm/src/photo/photo.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { PhotoService } from './photo.service'; 3 | import { PhotoController } from './photo.controller'; 4 | import { TypeOrmModule } from '@nestjs/typeorm'; 5 | import { Photo } from './photo.entity'; 6 | 7 | @Module({ 8 | imports: [TypeOrmModule.forFeature([Photo])], 9 | providers: [PhotoService], 10 | controllers: [PhotoController], 11 | }) 12 | export class PhotoModule {} 13 | -------------------------------------------------------------------------------- /packages/core/test/helpers/application-ref-host.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { HttpAdapterHost } from '../../helpers/http-adapter-host'; 3 | 4 | describe('HttpAdapterHost', () => { 5 | const applicationRefHost = new HttpAdapterHost(); 6 | it('should wrap application reference', () => { 7 | const ref = {}; 8 | applicationRefHost.httpAdapter = ref as any; 9 | 10 | expect(applicationRefHost.httpAdapter).to.be.eql(ref); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /sample/05-sql-typeorm/src/users/users.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { TypeOrmModule } from '@nestjs/typeorm'; 3 | import { User } from './user.entity'; 4 | import { UsersController } from './users.controller'; 5 | import { UsersService } from './users.service'; 6 | 7 | @Module({ 8 | imports: [TypeOrmModule.forFeature([User])], 9 | providers: [UsersService], 10 | controllers: [UsersController], 11 | }) 12 | export class UsersModule {} 13 | -------------------------------------------------------------------------------- /sample/07-sequelize/src/users/users.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { SequelizeModule } from '@nestjs/sequelize'; 3 | import { User } from './user.model'; 4 | import { UsersController } from './users.controller'; 5 | import { UsersService } from './users.service'; 6 | 7 | @Module({ 8 | imports: [SequelizeModule.forFeature([User])], 9 | providers: [UsersService], 10 | controllers: [UsersController], 11 | }) 12 | export class UsersModule {} 13 | -------------------------------------------------------------------------------- /sample/11-swagger/src/cats/cats.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { Cat } from './classes/cat.class'; 3 | import { CreateCatDto } from './dto/create-cat.dto'; 4 | 5 | @Injectable() 6 | export class CatsService { 7 | private readonly cats: Cat[] = []; 8 | 9 | create(cat: CreateCatDto): Cat { 10 | this.cats.push(cat); 11 | return cat; 12 | } 13 | 14 | findOne(id: number): Cat { 15 | return this.cats[id]; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sample/26-queues/src/audio/audio.module.ts: -------------------------------------------------------------------------------- 1 | import { BullModule } from '@nestjs/bull'; 2 | import { Module } from '@nestjs/common'; 3 | import { AudioController } from './audio.controller'; 4 | import { AudioProcessor } from './audio.processor'; 5 | 6 | @Module({ 7 | imports: [ 8 | BullModule.registerQueue({ 9 | name: 'audio', 10 | }), 11 | ], 12 | controllers: [AudioController], 13 | providers: [AudioProcessor], 14 | }) 15 | export class AudioModule {} 16 | -------------------------------------------------------------------------------- /integration/scopes/src/request-chain/request-chain.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { HelperModule } from './helper/helper.module'; 3 | import { RequestChainController } from './request-chain.controller'; 4 | import { RequestChainService } from './request-chain.service'; 5 | 6 | @Module({ 7 | imports: [HelperModule], 8 | providers: [RequestChainService], 9 | controllers: [RequestChainController], 10 | }) 11 | export class RequestChainModule {} 12 | -------------------------------------------------------------------------------- /integration/scopes/src/transient/users/user-by-id.pipe.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ArgumentMetadata, 3 | Injectable, 4 | PipeTransform, 5 | Scope, 6 | } from '@nestjs/common'; 7 | 8 | @Injectable({ scope: Scope.TRANSIENT }) 9 | export class UserByIdPipe implements PipeTransform { 10 | static COUNTER = 0; 11 | constructor() { 12 | UserByIdPipe.COUNTER++; 13 | } 14 | 15 | transform(value: string, metadata: ArgumentMetadata) { 16 | return value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sample/13-mongo-typeorm/src/photo/photo.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { TypeOrmModule } from '@nestjs/typeorm'; 3 | import { PhotoService } from './photo.service'; 4 | import { PhotoController } from './photo.controller'; 5 | import { Photo } from './photo.entity'; 6 | 7 | @Module({ 8 | imports: [TypeOrmModule.forFeature([Photo])], 9 | providers: [PhotoService], 10 | controllers: [PhotoController], 11 | }) 12 | export class PhotoModule {} 13 | -------------------------------------------------------------------------------- /sample/23-graphql-code-first/src/recipes/dto/new-recipe.input.ts: -------------------------------------------------------------------------------- 1 | import { Field, InputType } from '@nestjs/graphql'; 2 | import { IsOptional, Length, MaxLength } from 'class-validator'; 3 | 4 | @InputType() 5 | export class NewRecipeInput { 6 | @Field() 7 | @MaxLength(30) 8 | title: string; 9 | 10 | @Field({ nullable: true }) 11 | @IsOptional() 12 | @Length(30, 255) 13 | description?: string; 14 | 15 | @Field(type => [String]) 16 | ingredients: string[]; 17 | } 18 | -------------------------------------------------------------------------------- /sample/24-serve-static/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ServeStaticModule } from '@nestjs/serve-static'; 3 | import { join } from 'path'; 4 | import { AppController } from './app.controller'; 5 | 6 | @Module({ 7 | imports: [ 8 | ServeStaticModule.forRoot({ 9 | rootPath: join(__dirname, '..', 'client'), 10 | exclude: ['/api*'], 11 | }), 12 | ], 13 | controllers: [AppController], 14 | }) 15 | export class AppModule {} 16 | -------------------------------------------------------------------------------- /sample/26-queues/src/audio/audio.controller.ts: -------------------------------------------------------------------------------- 1 | import { InjectQueue } from '@nestjs/bull'; 2 | import { Controller, Post } from '@nestjs/common'; 3 | import { Queue } from 'bull'; 4 | 5 | @Controller('audio') 6 | export class AudioController { 7 | constructor(@InjectQueue('audio') private readonly audioQueue: Queue) {} 8 | 9 | @Post('transcode') 10 | async transcode() { 11 | await this.audioQueue.add('transcode', { 12 | file: 'audio.mp3', 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration/scopes/src/circular-transient/users/user-by-id.pipe.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ArgumentMetadata, 3 | Injectable, 4 | PipeTransform, 5 | Scope, 6 | } from '@nestjs/common'; 7 | 8 | @Injectable({ scope: Scope.TRANSIENT }) 9 | export class UserByIdPipe implements PipeTransform { 10 | static COUNTER = 0; 11 | constructor() { 12 | UserByIdPipe.COUNTER++; 13 | } 14 | 15 | transform(value: string, metadata: ArgumentMetadata) { 16 | return value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/core/errors/exceptions/circular-dependency.exception.ts: -------------------------------------------------------------------------------- 1 | import { RuntimeException } from './runtime.exception'; 2 | 3 | export class CircularDependencyException extends RuntimeException { 4 | constructor(context?: string) { 5 | const ctx = context ? ` inside ${context}` : ``; 6 | super( 7 | `A circular dependency has been detected${ctx}. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()".`, 8 | ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/core/router/interfaces/route-params-factory.interface.ts: -------------------------------------------------------------------------------- 1 | import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum'; 2 | 3 | export interface IRouteParamsFactory { 4 | exchangeKeyForValue< 5 | TRequest extends Record = any, 6 | TResponse = any, 7 | TResult = any 8 | >( 9 | key: RouteParamtypes | string, 10 | data: any, 11 | { req, res, next }: { req: TRequest; res: TResponse; next: Function }, 12 | ): TResult; 13 | } 14 | -------------------------------------------------------------------------------- /sample/04-grpc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /sample/08-webpack/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | declare const module: any; 5 | 6 | async function bootstrap() { 7 | const app = await NestFactory.create(AppModule); 8 | await app.listen(3000); 9 | console.log(`Application is running on: ${await app.getUrl()}`); 10 | 11 | if (module.hot) { 12 | module.hot.accept(); 13 | module.hot.dispose(() => app.close()); 14 | } 15 | } 16 | bootstrap(); 17 | -------------------------------------------------------------------------------- /sample/14-mongoose-base/src/cats/cats.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CatsController } from './cats.controller'; 3 | import { CatsService } from './cats.service'; 4 | import { catsProviders } from './cats.providers'; 5 | import { DatabaseModule } from '../database/database.module'; 6 | 7 | @Module({ 8 | imports: [DatabaseModule], 9 | controllers: [CatsController], 10 | providers: [CatsService, ...catsProviders], 11 | }) 12 | export class CatsModule {} 13 | -------------------------------------------------------------------------------- /sample/15-mvc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /sample/20-cache/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /sample/26-queues/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /integration/nest-application/get-url/e2e/utils.ts: -------------------------------------------------------------------------------- 1 | import * as net from 'net'; 2 | 3 | export let port: number; 4 | 5 | export async function randomPort(): Promise { 6 | const server = net.createServer(); 7 | return new Promise((resolve, reject) => { 8 | if (port) { 9 | resolve(port); 10 | } 11 | server.listen(0, () => { 12 | port = (server.address() as net.AddressInfo).port; 13 | server.close(); 14 | resolve(port); 15 | }); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /sample/01-cats-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /sample/02-gateways/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | --------------------------------------------------------------------------------