Skip to content
Snippets Groups Projects
Commit b54b8207 authored by Steve Reis's avatar Steve Reis
Browse files

Initial commit with initial Nest.js project

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 335 additions and 0 deletions
Title (to remove from description) : As a <type of user>, I want <a goal> so that <benefit>
**User Story**
**Acceptance Criteria**
**Definition of Done**
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
\ No newline at end of file
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
source diff could not be displayed: it is too large. Options to address this: view the blob.
{
"name": "dynamic",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/axios": "^0.0.1",
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/graphql": "^9.0.4",
"@nestjs/platform-express": "^8.0.0",
"@nestjs/typeorm": "^8.0.2",
"apollo-server-express": "^3.3.0",
"axios": "^0.21.1",
"graphql": "^15.5.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.1",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
import { HttpService } from "@nestjs/axios";
import { IEngineOptions, IEngineService } from "src/engine/engine.interface";
export default class DataShieldService implements IEngineService {
constructor(private readonly options: IEngineOptions, private readonly httpService: HttpService) { }
demo(): string {
return "datashield";
}
}
\ No newline at end of file
import { HttpService } from "@nestjs/axios";
import { IEngineOptions, IEngineService } from "src/engine/engine.interface";
export default class ExaremeService implements IEngineService {
constructor(private readonly options: IEngineOptions, private readonly httpService: HttpService) { }
demo(): string {
return "exareme"
}
}
\ No newline at end of file
export const ENGINE_MODULE_OPTIONS = "EngineModuleOption";
export const ENGINE_SERVICE = "EngineService"
\ No newline at end of file
import { HttpService } from '@nestjs/axios';
import { Controller, Get, Inject } from '@nestjs/common';
import { ENGINE_SERVICE } from './engine.constants';
import { IEngineService } from './engine.interface';
@Controller()
export class EngineController {
constructor(@Inject(ENGINE_SERVICE) private readonly engineService: IEngineService, private readonly httpService: HttpService) { }
@Get("/test")
getTest(): string {
return this.engineService.demo();
}
}
import { AxiosResponse } from "axios";
import { Observable } from "rxjs";
export interface IEngineOptions {
type: string;
}
export interface IEngineService {
demo(): string;
}
\ No newline at end of file
import { HttpModule, HttpService } from '@nestjs/axios';
import { DynamicModule, Global, Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path';
import { ENGINE_MODULE_OPTIONS, ENGINE_SERVICE } from './engine.constants';
import { EngineController } from './engine.controller';
import { IEngineOptions, IEngineService } from './engine.interface';
import { EngineResolver } from './engine.resolver';
@Global()
@Module({})
export class EngineModule {
static async forRootAsync(options: IEngineOptions): Promise<DynamicModule> {
const optionsProvider = {
provide: ENGINE_MODULE_OPTIONS,
useValue: options,
};
const engineProvider = {
provide: ENGINE_SERVICE,
useFactory: async (httpService: HttpService) => {
return await this.createEngineConnection(options, httpService)
},
inject: [HttpService]
};
return {
module: EngineModule,
imports: [
HttpModule,
GraphQLModule.forRoot({
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
}),
],
providers: [
optionsProvider,
engineProvider,
EngineResolver
],
controllers: [
EngineController
],
exports: [optionsProvider, engineProvider],
}
}
private static async createEngineConnection(options: IEngineOptions, httpService: HttpService): Promise<IEngineService> {
let service = await import(`./connectors/${options.type}/main.connector`);
return new service.default(options, httpService);
}
}
import { Inject } from '@nestjs/common';
import { Query, Resolver } from '@nestjs/graphql';
import { ENGINE_SERVICE } from './engine.constants';
import { IEngineService } from './engine.interface';
@Resolver()
export class EngineResolver {
constructor(@Inject(ENGINE_SERVICE) private readonly engineService: IEngineService) { }
@Query(() => String)
async hello() {
return this.engineService.demo();
}
}
\ No newline at end of file
import { NestFactory } from '@nestjs/core';
import { AppModule } from './main/app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
import { HttpService } from '@nestjs/axios';
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) { }
@Get()
getHello(): string {
return this.appService.getHello();
}
}
import { Module } from '@nestjs/common';
import { EngineModule } from 'src/engine/engine.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [
EngineModule.forRootAsync({
type: process.env.ENGINE_TYPE || "exareme"
})],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment